Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Monday December 30, 2002
04:06 AM

Not the brightest bulb in the socket

[ #9671 ]

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.

use LWP::Simple;
my $base = "";
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";