http://qs321.pair.com?node_id=584905


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.