|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
I'm not familiar w/ perl, does anyone know how to convert this php code into perl ?
<? //put file in array $fcontents = file ('http://www.domain.com/file_to_print.php3'); //print each lines while ( list( $line_num, $line ) = each( $fcontents ) ) { $val = stripslashes( $line ); echo $val; } ?> I'm trying to read & print output from a file that is located on another site in order to share news between my domains. |
|
#2
|
|||
|
|||
|
You have to use the excellent LWP module set (well, you don't _have_ to, but it'd be damn silly not to). Something like:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent('SomeUAString' . $ua->agent); my $req = HTTP::Request->new( GET => 'http://www.domain.com/somefile.php3' ); my $res = $ua->request($req); print $res->content; [/code] I'm not sure what stripslashes does for you in PHP (I don't do PHP). If you let me know I'll give you equivalent Perl code. If it's just used to remove escape characters from the stream (e.g. ' => '), use: $res->content =~ s///g; before the prin $res->content line. Loads of docs on LWP can be found with perldoc LWP |
|
#3
|
|||
|
|||
|
thanx so much for your help.
(yes the 'stripslashes function' is to escape quote) |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > perl to read file (converting php codes) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|