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