Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Perl on Windows XP needs to grab internet txt file.

by DigitalKitty (Parson)
on Feb 02, 2008 at 00:37 UTC ( [id://665687]=note: print w/replies, xml ) Need Help??


in reply to Perl on Windows XP needs to grab internet txt file.

Ahoy kansaschuck!

LWP::Simple is an extremely useful module and I highly recommend using it for your http related needs. To retrieve a file from a remote server, the following code would work well:
#!/usr/bin/perl use warnings; use strict; use LWP::Simple; my $url = ''; my $file = ''; my $resp = ''; print 'Please enter a URL: '; chomp( $url = <STDIN> ); print 'Please enter a filename in which to store the data: '; chomp( $file = <STDIN> ); # We don't want to overwrite a file that already exists so using the ' +-e' essentially asks: Does a file of this name # already exist? If so, the message is displayed and the program exits +. if( -e $file ) { die "Sorry. That filename already exists.\n"; } # The 'getstore' function returns an http response code e.g. 200, 404, + etc. # The syntax says: Store the data obtained from '$url' in '$file'. $resp = getstore( $url, $file ); exit;


Hope this helps,

~Katie

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-28 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found