mdbtxt1
mdbtxt2
Proceed to Safety

SimpleGet.pl Examples    

The following are a set of simple example Perl programs using the SimpleGet library.

This one prints the current top story on CNN's website (subject to change, whenever CNN changes their website format). #!/usr/bin/perl require "SimpleGet.pl"; $_ = get("http://www.cnn.com/"); s/^.*&lt;H3&gt;//s; s/FULL STORY.*$//s; s/<[^>]+>//g; s/\n[ \t\n\r]+/\n/g; print;

From the O'Reilly book "Perl in a Nutshell": #!/usr/bin/perl require "SimpleGet.pl"; $homepage = 'oreilly_com.html'; $status = getstore('http://www.oreilly.com/', $homepage); print("hooray\n") if is_success($status);

This one's inspired by the Operating System Sucks-Rules-O-Meter, which was responsible for me creating SimpleGet.pl in the first place! #!/usr/bin/perl require "SimpleGet.pl"; $| = 1; print "Checking... "; $query = qq{http://altavista.digital.com/cgi-bin/query}; $query .= qq{?pg=q&what=web&kl=XX&q=%2B%22}; get($query . "windows.sucks%22") =~ m/([\d\,]+)\D+pages\s+found/; $_ = $1; s/\D+//; $s_count = $_; get($query . "windows.rules%22") =~ m/([\d\,]+)\D+pages\s+found/; $_ = $1; s/\D+//; $r_count = $_; if ($s_count > $r_count) { print "\nMicrosoft Windows still sucks.\n"; } else { print "\nYour Net access is broken. Call your ISP.\n"; }

The weather example from The Perl Journal issue #13 no longer works, so here's an alternative that uses your zipcode as the parameter: #!/usr/bin/perl # # 6-day forecast from the Weather Channel. Supply zipcode on # command line, like so: # # weather.pl 02134 # require "SimpleGet.pl"; $_ = get("http://www.weather.com/weather/us/zips/$ARGV[0].html"); s/<[^>]+>//g; s/^.*FORECAST//s; s/Send us your.*//s; s/&amp;deg;/"/g; s/\n[ \t\n\r]+/\n/g; s/&nbsp;/ /g; print "$_\n";


Robert Munafo's home pages on AWS    © 1996-2024 Robert P. Munafo.    about    contact
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Details here.

This page was written in the "embarrassingly readable" markup language RHTF, and was last updated on 2010 Jan 30. s.27