Not the brightest bulb in the socket

brian_d_foy on 2002-12-30T09:06:24

I have been writing a lot of little tool scripts lately. It takes me awhile to figure out that I am doing the same thing over and over again, and then even longer to get around to actually automating the process. Not too swift on the uptake.

This particular time consuming task involved going to a web site, using a form to search for a document, download the document as part of a ZIP archive, make a directory for it, then unzip the file. I have done that by hand for approximately 200 files. I got tired of that a long time ago, and now I have taken the five minutes to write the script to do it for me.

I left most of the robust error checking out---that final 20% of the work. In this case the 80% done works well enough for me. I could also write this as a shell script, but it is so much easier in Perl.

#!/usr/bin/perl

use LWP::Simple;

my $base = "https://www.example.com"; my $dir = "$ENV{HOME}/Foo";

foreach my $file ( @ARGV ) { $file = lc $file; mkdir "$dir/$file", 0755 or warn "Could not make [$dir/$file]: $!"; my $result = getstore( "$base/$file/$file.exe", "$dir/$file/$file.exe" ); print "$file ", $result == 200 ? "OK" : "OOPS! - $result", "\n"; chdir "$dir/$file" or die "Could not change directory!"; system "unzip", "$dir/$file/$file.exe"; }