From: David Mertens
Sent: Friday, July 07, 2017 12:07 PM
To: Sisyphus
Cc: Chas. Owens ; hw ; Perl Beginners
Subject: Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i:
$i\n";'
On Thu, Jul 6, 2017 at 9:12 PM, <sisyph...@optusnet.com.au> wrote:
I find it a little surprising that use of the '!' operator is all that's
needed to add the stringification stuff:
...
If the '!' operator didn't do that, then I believe the OP would be seeing
precisely what he expects.
So ... why should the '!' operator *not* respect the string/numeric
context of the operand ?
Perl is highly unusual in that the operator, not the operand, dictates the
context.
Good point - and one that I hadn't got around to noticing.
Therefore, the '!' operator has to be set up to either:
a) operate always in numeric context;
or
b) operate always in string context;
or
c) operate always in both contexts (as per the current behaviour).
Having an ambivalent '!' operator (where it alternates between a) and b),
according to the operand's flags) is therefore not an option.
If we wanted an operator for "logical string negation" and an operator for
"logical numeric negation" we would need 2 different operators.
Have I got that somewhere near right ?
Cheers,
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/