Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: using Perl::Tidy/perltidy()

by Aldebaran (Deacon)
on Apr 19, 2012 at 19:10 UTC ( #966034=note: print w/replies, xml ) Need Help??

in reply to Re: using Perl::Tidy/perltidy()
in thread using Perl::Tidy/perltidy()

Thx toolic, I was reading the example page wrong and missed that my file was there with a tdy suffix. Looks like it's all straightened out now:

$ perltidy -b $ perl downloaded 2 images from to folder site_5 $ echo "wow, that's minimal." wow, that's minimal. $ cat #!/usr/bin/perl -w # creates a new directory and downloads images from url to it # perlmonks node 965537; thx aaron and A.M. use strict; use feature ':5.10'; use WWW::Mechanize; use LWP::Simple; use Errno qw[ EEXIST ]; # get information about images my $domain = ''; my $m = WWW::Mechanize->new(); $m->get($domain); my @list = $m->images(); # create new folder and download images to it. my $counter = 0; my $dir = &mk_new_dir; 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"; } # output print "downloaded ", $counter, " images from ", $domain, "\n"; print "to folder ", $dir, "\n"; sub mk_new_dir { my $counter2 = 1; while (1) { my $word = "site"; my $name = $word . '_' . $counter2++; if ( mkdir $name, 0755 ) { return $name; # success, return new dir name } else { next if $!{EEXIST}; # mkdir failed because file exists die sprintf "(%d) %s", $!, $!; # other failure; bail ou +t! } } } $

I think, if I were going to change anything, it might be the number of spaces (or tab-length, whichever it is) after a statement and before a right comment and maybe go from 4 to 3 spaces for a general indenting. You can see that I have a bit of fold-over in the display (not real fold-over with a newline tho)

Let me ask this. Are there specific choices that matter a whole bunch in the negative sense here. For example, if I went with -i3 indenting, are there people that matter out there who would say, "gosh, the perl here is one thing, but this 3-space indenting is giving me a headache and crossing my eyes. What moron does that when he could have done 2 or 4: nice even numbers?"?

Replies are listed 'Best First'.
Re^3: using Perl::Tidy/perltidy()
by GrandFather (Saint) on Apr 19, 2012 at 23:13 UTC

    A 4 space indent is fairly conventional in the Perl world, but really is not critical in any sense. In a C++ context I use a 3 space indent because 2 is too few for me to be able to see correctly a lot of the time and 4 leads to stuff disappearing off the right edge too fast. I use a 4 space indent for Perl because that is most common. Sometimes it is just best to go with the flow!

    Personally I really dislike white space on the inside of parenthesis ( like this ), but if you are going to do it at least be consistent (why should the rule be different for while than for for?).

    Where there is no other compelling reason to choose one formatting option over another I choose the one that results in code looking the most like conventionally formatted English prose. That is what I parse most and I figure the more my code parser is like my prose parser the fewer parsing errors I'll get.

    True laziness is hard work

      alright then, 4 it is. When you think about it, that's fine because you're not dealing with

      int main(){ c everything's indented in the main body return 0; }

      nor does perl have the nested looping that you see so much with explicit indices. In reading the camel and llama book, I don't think I've seen nesting beyond 2 levels.

      If anyone has what they think is an improvement over the default values that might be appropriate for someone coming up on acolyte status, I am--monkishly--all ears.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2021-03-07 12:36 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (121 votes). Check out past polls.