Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^10: Can't call method "proxy" on an undefined value at

by Anonymous Monk
on Feb 09, 2016 at 17:12 UTC ( [id://1154741]=note: print w/replies, xml ) Need Help??


in reply to Re^9: Can't call method "proxy" on an undefined value at
in thread Can't call method "proxy" on an undefined value at

Thanks. I understand the concept and see that the shift would and almost have it working. I'm getting an explicit package name error on $proxies. I'm using my $proxies earlier in the script so I"m not sure why I'm getting the error. I'll keep trying. Here's what I have.

# create useragent my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/8.0'); # get pages for each city, keyword, proxy for my $city (@cities) { my $keyword = shift @keywords; my $proxy = shift @proxies; print "City : [$city]\nKeyword: [$keyword]\n"; print "Current proxy:$proxies\n"; # Use this UA/Proxy to fetch something.... $ua->proxy(['http'], 'http://'.$proxies); my $url = join '',$link1 . $city ."+". $keyword, $link2 . $city ."+". $keyword, $link3; my $response = $ua->get($url); print "getting $url\n"; if ($response->is_success) { my $filename = "Bing/${city}_${keyword}.html"; print "Creating $filename\n"; open my $fh, ">", $filename or die("Could not open $filename. $!"); print $fh $response->decoded_content; # or whatever close $fh; } else { die $response->status_line; } print "\n"; } close($fh);

These two lines are causing the errors:

print "Current proxy:$proxies\n"; # Use this UA/Proxy to fetch something.... $ua->proxy(['http'], 'http://'.$proxies);

Replies are listed 'Best First'.
Re^11: Can't call method "proxy" on an undefined value at
by choroba (Cardinal) on Feb 09, 2016 at 17:18 UTC
    @proxies, $proxy, and $proxies are three different variables.
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re^11: Can't call method "proxy" on an undefined value at
by poj (Abbot) on Feb 09, 2016 at 17:16 UTC

    @proxies is the array. Use

    print "Current proxy:$proxy\n"; # Use this UA/Proxy to fetch something.... $ua->proxy(['http'], 'http://'.$proxy);
    poj
Re^11: Can't call method "proxy" on an undefined value at
by Anonymous Monk on Feb 09, 2016 at 17:17 UTC

    OK, got it!

    # get pages for each city, keyword, proxy for my $city (@cities) { my $keyword = shift @keywords; my $proxy = shift @proxies; print "City : [$city]\nKeyword: [$keyword]\n"; print "Current proxy:$proxy)\n"; # Use this UA/Proxy to fetch something.... $ua->proxy(['http'], 'http://'.$proxy); my $url = join '',$link1 . $city ."+". $keyword, $link2 . $city ."+". $keyword, $link3; my $response = $ua->get($url); print "getting $url\n"; if ($response->is_success) { my $filename = "Bing/${city}_${keyword}.html"; print "Creating $filename\n"; open my $fh, ">", $filename or die("Could not open $filename. $!"); print $fh $response->decoded_content; # or whatever close $fh; } else { die $response->status_line; } print "\n"; } close($fh);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1154741]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-25 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found