Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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

by DigitalKitty (Parson)
on Feb 02, 2008 at 00:37 UTC ( #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,


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2023-03-28 21:46 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (69 votes). Check out past polls.