note
Aldebaran
<p>Yay! first taste of victory....</p>
<code>$ perl tg1.pl
site_13
$ cd site_13
$ ls
image_1 image_2 image_3 ...
$ cd ..
$ cat tg1.pl
#!/usr/bin/perl -w
use strict;
use WWW::Mechanize;
use LWP::Simple;
my $domain = 'http://www.yahoo.com';
my $m = WWW::Mechanize->new;
$m->get( $domain);
my $counter = 0;
my $dir = &dirname;
my @list = $m->images();
for my $img (@list) {
my $url = $img->url_abs();
$counter++;
my $filename = "$dir". "/image_". "$counter";
getstore($url,$filename) or die "Can't download '$url': $@\n";
}
sub dirname {
my $word = "site";
my $counter = 1;
my $flag = 1;
while ($flag) {
my $name = "$word" . "_" . "$counter";
if ( -d $name) {
$counter++;
next;
}
else {
mkdir $name, 0755 or warn "Cannot make dir $name: $!";
$flag = 0;
}
print "$name \n";
return $name;
}
}
$
</code>
<p>I have a whole bunch of questions at this point, but don't want to ask them all. Let me ask this one, because it goes to readability: Is there an indent command that works well for perl? indent -i2 foo.pl was not a winner.</p>
965118
965121