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

Re: How (Not) To Ask A Question

by chromatic (Archbishop)
on Nov 19, 2006 at 00:40 UTC ( [id://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"; }

Replies are listed 'Best First'.
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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://584905]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found