[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [ID 20000128.001] $a = 1,,,,,,,,,
cook@sightpath.com writes:
: Perl fails to reject this program:
:
: $a = 1,,,,,,,,
It also fails to reject these:
$a = (1,,,,,,,,)
$a = 1,2,3,4,5,6,7,8,9,
$a = 1,,,,,,,,,10,
: The superfluous commas just seem to be ignored.
Yes. This is a recursive consequence of the rule that any list can end
with a comma, which is ignored. And the fact that lists don't require
parens around them unless required by precedence. So don't take the
absence of parentheses for the absence of a list.
So your example is parsing as all these sublists:
($a = 1),(),(),(),(),(),(),(),()
which, after you interpolate all the null lists, is just the list
($a = 1)
which is, of course, no different from
$a = 1
: The camel says these are wrong (so I'm told; p528?):
That's talking specifically about putting a comma between a filehandle
and subsequent arguments.
: print $a, if s/x/y/;
: print, if s/x/y/;
:
: Yet perl accepts them.
Why not? There are no filehandles there, as far as Perl is concerned.
Just a list of size 1 and a list of size 0, either of which can end
with a comma.
Actually, now that I think about it, you can't actually start a list
with a comma, so the second one is probably parsing as (print),()
rather than print((),()). In which case that's a list of size 1 as well,
the first and only element of which is the bare print operator. After all,
if you said
print, next if s/x/y/
it would print $_ and then do a next, since next would not be considered
an argument to the print. That's why we don't allow lists to start with
a comma.
But they may certainly end with one. And since a list that ends with
a comma is a list, it can in turn end with a comma. And since a list
that ends with two commas is a list, it can in turn end with a comma.
Und so weiter...
Larry
- References to:
-
Michael Cook <cook@sightpath.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]