On Mon, Feb 03, 2003 at 11:08:37AM -0000, Rob Dixon wrote:
> Paul Johnson wrote:
> > But 5.10 will (probably) introducde the // operator which will allow
> > you to say:
> >
> > $var //= 10;
>
> Where do you get this insider information Paul?
Keeping up with development :-)
> And what's this operator
> going to do? Presumably there's an operator $c = $a // $b as well. I'm
> surprised if it's just (defined $a ? $a : $b).
This from the version of perlop in bleadperl (the current development
sources):
Although it has no direct equivalent in C, Perl's "//" operator is
related to its C-style or. In fact, it's exactly the same as "||",
except that it tests the left hand side's definedness instead of its
truth. Thus, "$a // $b" is similar to "defined($a) || $b" (except that
it returns the value of $a rather than the value of "defined($a)") and
is exactly equivalent to "defined($a) ? $a : $b". This is very useful
for providing default values for variables. If you actually want to test
if at least one of $a and $b is defined, use "defined($a // $b)".
The "||", "//" and "&&" operators differ from C's in that, rather than
returning 0 or 1, they return the last value evaluated. Thus, a
reasonably portable way to find out the home directory might be:
$home = $ENV{'HOME'} // $ENV{'LOGDIR'} //
(getpwuid($<))[7] // die "You're homeless!\n";
> Interested, of Tunbridge Wells.
Dear Points of View,
The testcard - another winner!
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]