Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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,

~Katie


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2015-07-06 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (77 votes), past polls