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.
In reply to Re: Inconsistency in warning for parens with my.
by BrowserUk
in thread Inconsistency in warning for parens with my.
by davido
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |