#!/usr/bin/perl
# cookbook.pl - get and store daily cookbook recipes from perl.com
# files are saved as title_of_the_recipe.html
use strict;
use LWP::Simple 'get';
my $path = "/full/path/to/cookbook"; # CHANGE
my $cook = "http://www.perl.com/pub/a/universal/pcb/solution.html";
my $cooked = get $cook or die;
$cooked =~ s|||oi;
$cooked =~ s|language="JavaScript"|language="foo"|gi;
$cooked =~ s| src="(.*?)"| src="blank.gif"|gi;
$cooked =~ s| href="/| href="http://www\.perl\.com/|gi;
$cooked =~ m/
.*[^<]/oi;
my $title = $&;
chomp title;
$title =~ s|
||oi;
$title =~ s|\W|_|g;
$title =~ s|^_||o;
my $save = "$title.html";
open(FILE,">$path/$save") or die;
print FILE $cooked;
close (FILE) or die;
exit;
#!/usr/bin/perl
# cookbooks.pl - list saved recipes
use CGI qw(:standard);
opendir DIR, "." or die "error reading dir: $!";
@files = readdir DIR;
closedir DIR;
foreach $file(@files){ if($file=~/.*\.html/){ if($file=~/^[A-Z]/){ push @recs,$file}}}
@recs=sort(@recs);
$uhh=scalar(@recs);
print header;
print start_html(-title=>'Recipes of the Day',-bgcolor=>'ffffff',-text=>'000000',-link=>'000000',-vlink=>'000000');
print<
$uhh Perl Cookbook Recipes
HTML
foreach $pe(@recs){
($fp=$pe)=~s/_|\.html$/ /g;
print qq~
$fp ~;
}
if($uhh==0){ print qq~Your recipes will be listed here, sorted alphabetically.~;}
print<