473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Passing text from perl to PHP

14
Hi

Just a quick question

Is it possible from a Perl script to take a line of text which is generated by this Perl script and pass it to a PHP script which will deal with the web side of things

I have the Perl script that gives the output test and I have the PHP file just need to combine the two

Both files are all on the same PC

Thanks Keith
May 13 '07 #1
10 1787
prn
254 Expert 100+
Hi Keith,

I'm sure it is possible. It's undoubtedly even easy, but it's really a PHP question, not a Perl question. Since it's a web application, it will be controlled by whatever routine handles the web request and you said that you have a PHP routine that handles the web end of it. The workflow of any web request is:
Expand|Select|Wrap|Line Numbers
  1. webserver gets http request
  2. webserver passes http parameters to handler
  3. handler does work
  4. handler passes result back to webserver
  5. webserver passes data to requester
  6.  
Now this is all very oversimplified, but basically your handler seems to be a PHP routine and that farms out some of its work to a Perl routine, right? I know of no constraints that require ALL of the backend work to be done by Perl or ALL by PHP. It would certainly be possible for most any webserver to pass some requests to a PHP routine and others directly to a Perl routine. So I'm just taking you at your word on your description of the division of labor here.

Anyway, whatever it is that the PHP routine does, it will need to parse out whatever it needs to pass to the Perl routine and call the Perl. Exactly how it does that may well depend on what it does and how it does it. I can easily imagine multiple possibilities if the division of labor were reversed. But since you are really asking a PHP question you are likely to get a better discussion in the PHP forum. You are asking how to call an external routine (with specified input parameters and output, the fact that it is written in Perl is pretty much irrelevant) from a PHP routine that does ...? I'm sure they will need more detail about what kinds of parameters you need to pass and what kind of result you expect to get back.

Sorry I couldn't answer your quesiton more directly, but those are the sorts of questions I'd give back to you if it were a Perl quesiton.

Best Regards,
Paul
May 14 '07 #2
Guern1
14
Thanks for the help Paul

What i want to achieve to something like below

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl 
  2. use strict; 
  3. use LWP::Simple; 
  4. my $url = post('http://www.help.net/cgi-bin/read.cgi') or die "Couldn’t send to page."; 
  5.  
I don’t want to read the page I want to send to it

where my script connects and sends the information to a web page
The Perl script generates an output from a database type programme and I would like to send the output to a web page

I have looked at alot of information and think I am getting confused with post etc used in HTML code

If somebody could point me in the right direction it would be most appreciated

Thanks

Keith
May 14 '07 #3
prn
254 Expert 100+
Ah! So you don't really care at all what is running on the webserver. You are just trying to send data to a webserver that collects the data you send it? If your interaction with a webserver is just through the CGI interface, it really doesn't matter whether the script behind the page is PHP, Perl, C or whatever.

Does the form you are sending to require POST? If you need to use a POST method, then you are using the wrong module. LWP::Simple does not have a POST method. See perlfaq9 on that topic. There is a module LWP::Simple::Post that you might be able to use.

Alternatively, you might check out Getting more out of LWP::Simple, which does have some suggestions including the fact that web scripts often don't really care if you submit using GET instead of POST. It's probably worthwhile reading in any case.

HTH,
Paul
May 15 '07 #4
KevinADC
4,059 Expert 2GB
Both files are all on the same PC
Sounds like you just need to write the results of the perl program to a file/database and have your PHP program open the file. Why are you trying to do this via http/cgi?
May 15 '07 #5
Guern1
14
Hi Kevin

Thanks for the advice

Being new to Perl but having done some HTML I have got myself into a bit of a mess on this one its a case of a little knowledge is dangerous.

I was thinking of trying to post the information from one type of script to another a bit like using a web form to a CGI script for further processing.

I will work it out its all part of the learning process a few pointers from you experts usually puts me on the right track

Thanks again

Keith
May 15 '07 #6
Guern1
14
Hi

Ok I am making progress here but I am stuck again

Belowe is what i have come up with and it works fine doing just want i want it to do.

Expand|Select|Wrap|Line Numbers
  1.  sub send_other 
  2. {
  3. my $dest = shift;
  4. my $msg = shift;
  5.  
  6.  
  7. # start a new sms message
  8.  
  9. use LWP::UserAgent;
  10. use HTTP::Request::Common;
  11. use URI::Escape;
  12.  
  13. # format sms message
  14.  
  15. $post_data = ();
  16. $post_data{'sdn'} = "+447781100000";
  17. $post_data{'message'} = " this is my messsage !";
  18. $post_type = "http://";
  19. @post_servers = ("me.me.com", "me.me.com",
  20. "me.me.com", "me.me.com");
  21. $post_path = "/sms1.php";
  22. my $ua = LWP::UserAgent->new(agent => 'dxg perl client');
  23. foreach $server (@post_servers) {
  24. my $resp = $ua->request(
  25. POST $post_type.$server.$post_path,
  26. Content_Type => 'form-data',
  27. Content => [ %post_data ]
  28. );
  29. if ($resp->is_success) {
  30. print $resp->content;
  31. last;
  32. } else {
  33. print "Error: ".$post_type.$server.$post_path." -
  34. ".$resp->status
  35. print "Error: ".$post_type.$server.$post_path." -
  36. ".$resp->status_line."\n";
  37. }
  38. }
  39. }
  40.  
Now when I put this section of perl into the main script and runit i get the following messages and don't understand why

Global symbol "$post_data" requires explicit package name at DXGateway.pl line 1521.
Global symbol "%post_data" requires explicit package name at DXGateway.pl line 1522.
Global symbol "%post_data" requires explicit package name at DXGateway.pl line 1523.
Global symbol "$post_type" requires explicit package name at DXGateway.pl line 1524.
Global symbol "@post_servers" requires explicit package name at DXGateway.pl line 1525.
Global symbol "$post_path" requires explicit package name at DXGateway.pl line 1527.
Global symbol "$server" requires explicit package name at DXGateway.pl line 1529.
Global symbol "@post_servers" requires explicit package name at DXGateway.pl line 1529.
Global symbol "$post_type" requires explicit package name at DXGateway.pl line 1531.
Global symbol "$server" requires explicit package name at DXGateway.pl line 1531.
Global symbol "$post_path" requires explicit package name at DXGateway.pl line 1531.
Global symbol "%post_data" requires explicit package name at DXGateway.pl line 1533.
Global symbol "$post_type" requires explicit package name at DXGateway.pl line 1539.
Global symbol "$server" requires explicit package name at DXGateway.pl line 1539.
Global symbol "$post_path" requires explicit package name at DXGateway.pl line 1539.
syntax error at DXGateway.pl line 1541, near "->status

why if it runs stand alone does it now give so many errors

Any thoughts?

Many thanks

Keith
May 16 '07 #7
KevinADC
4,059 Expert 2GB
it's because your main program is using "strict" which is a good thing. So all the lexical variables must be declared with "my" just like you started doing here:


Expand|Select|Wrap|Line Numbers
  1. sub send_other {
  2.    my $dest = shift;
  3.    my $msg = shift;
May 16 '07 #8
Guern1
14
Hi Kevin

Could you give us an example I have tried info from your last post now i get syntax error near "$post_data{"

Thanks

Keith
May 16 '07 #9
Guern1
14
Thanks all for your help

I have now have this script running and doing what I want.
It may not be the best example ever written but its working.

Many thanks for all the help

Keith
May 16 '07 #10
miller
1,089 Expert 1GB
Change line 15

Expand|Select|Wrap|Line Numbers
  1. $post_data = ();
  2.  
to

Expand|Select|Wrap|Line Numbers
  1. my %post_data = ();
  2.  
- Miller
May 16 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: google_nospam | last post by:
Thanks in advance for any help. I'm looking for a way to pass data from php to perl. Basically, I want to take some dynamic data from a database, mixed with user input, then reformat it to make a...
1
by: Romuald Favre | last post by:
Hi there, I just installed Perl (v. 5.6.1. built for MSWin32 from ActiveState) on a new server Windows 2000. Amazingly the passing of arguments doesn't work ! I saved the following code in a...
26
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function...
3
by: stahl.karl | last post by:
I have a CGI/Perl program that returns a string output. Is it possible to get this into a Javascript variable, where the name of the variable is defined in the Javascript and not in the Perl code?...
6
by: roop1 | last post by:
Hello gits, I found this snippet that you offered to another person and I was wondering if it wouldn't work for me as well: <script type="text/javascript"> function...
8
by: Harch84 | last post by:
Hi I have a html page with javascript in it that assigns a set of coordinates to javascript variables. The question I have is how can I then send these variables to a Perl CGI script using a...
1
by: satish2112 | last post by:
Hi, I have a text-area which contains values from mysql database and 2 buttons, Edit and Update. When I click on the Edit button, I can edit the text-area (initially non-editable). After this,...
1
by: Xah Lee | last post by:
Text Processing with Emacs Lisp Xah Lee, 2007-10-29 This page gives a outline of how to use emacs lisp to do text processing, using a specific real-world problem as example. If you don't know...
3
by: vijayarl | last post by:
Hi all, i have perl script, which is used to send mail. its a command line utility. if we run this perl script in command line by passing all it's required arguments, it works very well.there no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.