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

Hi monk,

Can anyone give an example of the use of this module 'LWP::Simple '. I would like it to get from an adrress and then stored it in a file.

Retitled by davido.

Replies are listed 'Best First'.
Re: Example using LWP::Simple
by gellyfish (Monsignor) on Jan 10, 2005 at 16:59 UTC

    You want to read about the getstore() function in the LWP::Simple documentation.

    /J\

Re: Example using LWP::Simple
by tall_man (Parson) on Jan 10, 2005 at 16:59 UTC
    Here is a one-liner from the LWP::Simple cpan page.
    perl -MLWP::Simple -e 'getprint "http://www.sn.no"' > out.htm
Re: Example using LWP::Simple
by punkish (Priest) on Jan 10, 2005 at 16:58 UTC
    Here is a simple example I use to grab the currently playing song on KCRW.com and display it on the console window as well as write it to a playlists file

    #!perl use strict; use LWP::Simple; my $url = 'http://www.kcrw.com/'; my $sleep_time = 120; my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = loc +altime; my $playlist = 'playlist.txt'; # What do you want to find out about my $start = "<a href=\"javascript:KCRWmusicAlbum.*\">"; my $stop1 = "<\/a> by <a href=\"javascript:KCRWmusicArtist.*\">"; my $stop2 = "<\/a> at"; my @playlist; my $last_song; while ($hour < 14) { # only until 2p central die "Couldn't get $url" unless (my $content = get $url); # search the $content for the $kw $content =~ m/$start(.*)$stop1(.*)$stop2/i; if ($1 ne $last_song) { my %song = ('SONG' => $1, 'SINGER' => $2); push(@playlist, \%song); $last_song = $1; print "Now playing: '$1' by $2\n"; open PL, ">>$playlist" or die "Cannot open $playlist: $!"; print PL "$1|$2\n"; close PL; } sleep $sleep_time; }
Re: Example using LWP::Simple
by Anonymous Monk on Jan 10, 2005 at 19:38 UTC

    What follows is a sample use of LWP::Simple.

    use LWP::Simple;

    Enjoy.