Hello good people
I've glanced at other people's posts and must say that this is very low-brow in comparison to what others are able to do. I guess we all start somewhere. Most of this script works for me, but I haven't quite wrangles the subroutine to return a new directory, in particular, what happens is that the while loop never terminates:
$ perl tg1.pl Useless use of private variable in void context at tg1.pl line 33. site_138 site_139 site_140 site_141 ^C $ 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 @list = $m->images(); for my $img (@list) { my $url = $img->url_abs(); $counter++; my $dir = &dirname; 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 ( -e -d $name) { $counter++; next; } else { mkdir $name, 0755 or warn "Cannot make dir $name: $!"; $flag = '0'; } print "$name \n"; $name; } } $
I know that execution goes through the else clause because I have dozens of directories now. I believe that I have a correct form for making the $flag false in the same clause, but perl thinks that I do nothing to end this control. How come?
Also accepting any tips to make this more concise and readable. Thanks in advance,
In reply to getting a while loop to terminate by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |