Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: getting a while loop to terminate

by Datz_cozee75 (Monk)
on Apr 17, 2012 at 16:41 UTC ( #965532=note: print w/ replies, xml ) Need Help??


in reply to Re: getting a while loop to terminate
in thread getting a while loop to terminate

Yay! first taste of victory....

$ 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; } } $

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.


Comment on Re^2: getting a while loop to terminate
Download Code
Replies are listed 'Best First'.
Re^3: getting a while loop to terminate
by GrandFather (Sage) on Apr 18, 2012 at 01:18 UTC

    You may be looking for Perl::Tidy which does an excellent job of pretty printing Perl and is highly configurable.

    True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://965532]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-07-30 11:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls