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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.