Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How (Not) To Ask A Question

by chromatic (Archbishop)
on Nov 19, 2006 at 00:40 UTC ( #584905=note: print w/ replies, xml ) Need Help??


in reply to How (Not) To Ask A Question

I have a difficult time seeing this as "good" code:

while (<STDIN>) { chomp; if ($_ =~ /hello/) { &style1(); } else { &style2(); exit; } } sub style1() { print "hello\n"; } sub style2() { print "bye\n"; }

There's inconsistent brace styling, the useless use of & on subroutine calls, useless prototypes, and a useless use of $_ =~. I'm not sure if explictly using STDIN is helpful either; it depends on the intent of this program. I hate to miss out on magic ARGV behavior. I'm also not sure that chomp has any value in the code snippet.

How about:

while (<STDIN>) { unless (/hello/) { style2(); exit; } style1(); } sub style1 { print "hello\n"; } sub style2 { print "bye\n"; }


Comment on Re: How (Not) To Ask A Question
Select or Download Code
Re^2: How (Not) To Ask A Question
by Asim (Hermit) on Nov 20, 2006 at 19:52 UTC
    The brace issue appears to be deliberate, according to the note below that code snip:
    There are no rules that say you have to cuddle your opening braces or isolate them on the line below (style1 versus style2 from the example on the right) and both are accepted - the important thing to do is be consistent.

    ----Asim, known to some as Woodrow.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-07-30 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (230 votes), past polls