Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a script where I'm reading I'm reading a line from a file in a folder that contains multiple lines and trying to then read a proxy address from a file and use it to look up the line which is a URL. It looks like I'm getting multiple proxy addressed back and I can't tell if they're being used for the look up.

Also with my chomp $row I'm trying to return just use lines that start with http. I"m working on that next. Here's my code. I'll continue to trouble shoot but would appreciate any guidance or assistance.

make_path('Bing/1Parsed/Html3/'); while (my $row = <$FILE>) { open my $fh1, ">", "Bing/1Parsed/Html3/$file.html" or die("Cou +ld not open file. $!"); chomp $row; print "$row\n"; my $xml1 = $row; $fh1->print ($row); #add pause my ( $x, $y ) = ( 2, 5 ); my $result = int( rand( $y - $x + 1 ) ) + +$x; print "pausing "; print $result; print "seconds"; sleep ($result); # create useragent my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/8.0'); # Use this UA/Proxy to fetch something.... $ua->proxy(['http'], 'http://'.$proxy); my $xml2 = get $xml1; #$fh1->print ($xml1); $fh1->print ("\n"); #$fh1->print ($fh1.$xml2); #$fh1->print ($fh1); print $xml2; $fh1->print ($xml2); #close $fh1, ">", "Ask/Parsed/Html/$file.h +tml"; close $fh1; $xml2=1; }}

Thanks in advance for any assistance.

  • Comment on reading a proxy address from a file and using in a while statement
  • Download Code

Replies are listed 'Best First'.
Re: reading a proxy address from a file and using in a while statement
by Athanasius (Archbishop) on Feb 10, 2016 at 07:49 UTC

    As NetWallah says, the code is very hard to follow. But these lines look wrong to me:

    while (my $row = <$FILE>) { open my $fh1, ">", "Bing/1Parsed/Html3/$file.html" or die("Could n +ot open file. $!");

    Since there is nothing to show that the value of $file changes within the while loop, the open statement recreates the same file and overwrites it on every loop iteration. (I’m also wondering whether it’s necessary to create a new instance of LWP::UserAgent on each iteration?)

    For future reference: please provide a short, self-contained script illustrating your problem. It’s also a really good idea (and not just for getting help at the Monastery!) to adopt an indentation style and follow it consistently.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: reading a proxy address from a file and using in a while statement
by NetWallah (Canon) on Feb 10, 2016 at 06:44 UTC
    Your code is undecipherable gibberish.

    You produce variables our of thin air ($proxy), and ponder:

    .....It looks like I'm getting multiple proxy addressed back and I can't tell if they're being used for the look up.

    If you can improve the coherence in your code, and questions, perhaps we may be a little more inclined to assist you.

            "Think of how stupid the average person is, and realize half of them are stupider than that." - George Carlin

      Thanks for the reply. Yes it's a piece of something bigger, I'll continue to work on it and if seeking help again will try and present it in a cleaner and more comprehensive fashion