Initial Revision
[ohcount] / test / expected_dir / perl1.pl / perl / code
1 use Time::ParseDate;
2 use Time::CTime;
3 use LWP::Simple;
4 $dir="/usr/local/etc/httpd/htdocs/Dilbert";
5 $location ="$dir/dilbert.gif";
6 $_ = get("http://www.unitedmedia.com/comics/dilbert/index.html");
7 s/^.*strip_left\.gif//s;
8 s/^.*?HREF=\"//s;
9 s/\">.*$//s;
10 $line = "http://www.unitedmedia.com" . $_;
11 #  Back up yesterday's image:
12 # get the number
13 open  (ID,"$dir/id");
14 $id=<ID>;
15 close ID;
16 $id++;
17 $id=~s/\n$//;
18 `mv $location $dir/dilbert.$id.gif`;
19 # If you're using this on NT, you may want to replace 'mv'
20 # with 'move'.
21 open (ID,">$dir/id");
22 print ID "$id";
23 close ID;
24 #  Now get the actual image
25 $_ = get($line);
26 open (FILE, ">$location");
27 binmode FILE; # Important for NT
28 print FILE;
29 close FILE;
30 # Now I want to update the index.html file
31 open (FILE, "$dir/index.html");
32 @index=<FILE>;
33 close FILE;
34 $yesterday = parsedate('yesterday');
35 $printdate = strftime('%a, %b %d', localtime($yesterday));
36 open (FILE, ">$dir/index.html");
37 for (@index)    {
38 if (/INSERT HERE/)      {
39 print FILE "$_";
40 print FILE "<td><a href=\"dilbert.$id.gif\">$printdate</a></td>\n";
41 if (($id % 5) == 0) {print FILE "</tr><tr>\n"}
42 }
43 else    {print FILE "$_"};
44 }  #  End for
45 close FILE;