[Melbourne-pm] The || operator
Damian Conway
thoughtstream at gmail.com
Mon Oct 31 15:23:32 PST 2005
Alfie John wrote:
> Looking through
> perlop, it says that this is the wrong way to use || and what would
> happen is:
>
> @a = scalar( (4,5,6) ) || (7,8,9);
Correct.
> and thus @a would contain 3.
Not correct. A series of commas in scalar context doesn't create a list, but
rather remains a series of scalars, only the last of which is returned as the
resulting scalar value.
But, yes, it's one of those places where DWIM fails in Perl 5. If it's any
comfort, it works correctly in Perl 6 (and already in Pugs):
#! /usr/local/bin/pugs
my @x = (4,5,7) || (1,2,3);
say @x.perl();
:-)
Damian
More information about the Melbourne-pm
mailing list