Bryan Harris wrote:
I found this construct in the Perl Cookbook:
$Current_Screen = param(".State") || "Default";
I thought it was really cool because if the value of
param(".State") comes back undefined, the $Current_Screen variable
gets set to "Default".
So the other day I wanted to do something similar:
@somearray = @array1 || @array2;
... hoping that if @array1 was empty, @somearray would get the
contents of @array2. But it doesn't work -- @somearray gets (1).
The construct makes @array1 be evaluated in scalar context, so the
result you mention indicates that @array1 contains one element.
It works fine with scalars:
$somescalar = $scalar1 || $scalar2;
With arrays, you can do for instance:
@somearray = @array1 ? @array1 : @array2;
(which basically is the same as if/else).
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>