#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    9
    Rep Power
    0
    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. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    81
    Rep Power
    15
    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
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    9
    Rep Power
    0
    thanx so much for your help.
    (yes the 'stripslashes function' is to escape quote)

IMN logo majestic logo threadwatch logo seochat tools logo