I can't explain why the warning behaves as I would want it to when 'or die' is appended, and not when it's left out.

First, this is nothing to do with open.

It simply comes down to the fact that when the parser sees the or, it knows that the second variable is a part of a compound statement. So it cannot be part of a list argument to the my, so it must be a separate term.

c:\test>perl -wE"my $a, $b or die;" Name "main::b" used only once: possible typo at -e line 1. Died at -e line 1.

Without the or to disambiguate, the second variable could be intended to be a part of a list argument to my, hence the warning is issued to persuade you to clarify

c:\test>perl -wE"my $a, $b;" Parentheses missing around "my" list at -e line 1. Useless use of a variable in void context at -e line 1. Name "main::b" used only once: possible typo at -e line 1.

Another way to disambiguate the syntax is to interpolate the second variable in quotes:

c:\test>perl -wE"my $a, qq[$b];" Useless use of string in void context at -e line 1. Name "main::b" used only once: possible typo at -e line 1. Use of uninitialized value $b in string at -e line 1.

Which just looks weird in isolation, but makes more sense when used in conjunction with open:

c:\test>perl -wE"open my $a, qq[> $b];" Name "main::b" used only once: possible typo at -e line 1. Use of uninitialized value $b in concatenation (.) or string at -e lin +e 1.

Other disambiguations are possible:

c:\test>perl -wE"open my $a, +$b;" Name "main::b" used only once: possible typo at -e line 1. Use of uninitialized value $b in open at -e line 1. c:\test>perl -wE"open my $a, ''.$b;" Name "main::b" used only once: possible typo at -e line 1. Use of uninitialized value $b in concatenation (.) or string at -e lin +e 1.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Inconsistency in warning for parens with my. by BrowserUk
in thread Inconsistency in warning for parens with my. by davido

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.