Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Strictly nested sub warnings

by GrandFather (Cardinal)
on Oct 05, 2010 at 22:37 UTC ( #863697=note: print w/ replies, xml ) Need Help??


in reply to Strictly nested sub warnings

Unrelated (directly) to your question, but in keeping with your desire to update your coding practises:

  1. Don't use subroutine prototypes. They probably don't do what you think.
  2. If you don't use prototypes you don't need to forward declare subs.
  3. Don't call subs using &subName. It probably doesn't do what you think either.
  4. Don't nest named subs, but you know that now.
  5. Generally use string interpolation instead of concatenation. For example: print "Found $params{numoLinks} Symbolic Links...\n";
  6. Initialise variables when you declare them. For example: my %params = (recurseDir => '.');
True laziness is hard work


Comment on Re: Strictly nested sub warnings
Select or Download Code
Re^2: Strictly nested sub warnings
by pobocks (Chaplain) on Oct 06, 2010 at 04:09 UTC

    Out of curiousity, why #5? I don't question that it's the case (you know better than me by job lots), I just wondered what the reason was.

    for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";
      Especially if you're joining lots of vars with short strings, concatenation can leave you drowning in symbols.
        For short variables I agree 100%.

        For more complex variables, I tend to go back to concatenation to make sure I get what I want.

        print "Guess what you get: $hashref->{$lookup1[$i]}->{$lookup2[$i]}\n" +;

        Also, with syntax highlighting, punctuation actually makes the code more readable than interpolation IMO.

        -- Time flies when you don't know what you're doing

      It's fairly minor, but using concatenation when you could use interpolation instead tends to obscure the result you are aiming for. Compare the following two print statements:

      use strict; use warnings; my $tsuJ = 'tsuJ'; my $rehtonA = 'rehtonA'; my $lreP = 'lreP'; my $rekcaH = "\nrekcaH"; print join ' ', map {scalar reverse} split / /, $tsuJ . ' ' . $rehtonA + . ' ' . $lreP . ' ' . $rekcaH; print join ' ', map {scalar reverse} split / /, "$tsuJ $rehtonA $lreP +$rekcaH";
      True laziness is hard work
Re^2: Strictly nested sub warnings
by raybies (Chaplain) on Oct 06, 2010 at 11:57 UTC

    It's probably a stupid question, but why not use prototypes?

    I like that I get some argument checking (not a whole lot, but that's actually better most of the time) by declaring named subs (i.e.  sub mySubroutine ($$) has two expected scalar args) with args, but I also like to stuff my subs at the bottom of my file, and so perl issues a warning if I don't put the prototype at the beginning of the code.

    Are you suggesting that to become more Perly, one must abandon naming arguments altogether in subs?

    Thanks again, all, for the suggestions. --Ray

        Thanks! I was just reading that exact node in the Meditations section... --Ray

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (15)
As of 2014-07-29 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (226 votes), past polls