Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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

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?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2020-09-25 20:23 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (140 votes). Check out past polls.