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 ""; $_ = get(""); 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 ""; $homepage = 'oreilly_com.html'; $status = getstore('', $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 in the first place! #!/usr/bin/perl require ""; $| = 1; print "Checking... "; $query = qq{}; $query .= qq{?pg=q&what=web&kl=XX&q=%2B%22}; get($query . "") =~ 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: # # 02134 # require ""; $_ = get("$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 HostMDS   © 1996-2017 Robert P. Munafo.
aboutcontact    mrob    mrob27    @mrob_27    mrob27
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 2017 Feb 02. s.11