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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.