Watch the precedence of your ors! Compare the following lines of code:
my $foo = $bar || die "Bela Lugosi is dead: $!"; my $FOO = $BAR or die "I'm dead, I'm dead, I'm dead";
s0ttle's code looks pretty good (but I haven't run it), and dragonchild's point about moving variable declarations to get the smallest scope possible is good too. But their use of open() || die makes me nervous.
Remember that || has a very high precedence and or has a low precedence. In the code at the top of my post, line 1 dies if $bar evaluates to false; line 2 dies if the assignment to $FOO fails.
I've been burned by using the || die syntax before. I kept doing it after some kindly monk (I forget who) warned me not to, and doomed myself to spend much time debugging as a result.
Like Cassandra, TGI says moo
In reply to or before ||, for || comes before or
by TGI
in thread beginner syntax question
by vectorvillain
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |