Hi!

You don't need logical string negotiation and logical number negotiation. You just need logical negotioation.

Using `!` operator to convert non-empty string to empty string is wrong, so as using `!` operator to convert not zero number to zero.

`!` operator is for logical operations only.


You don't want to use screwdriver to hammer in nails, just because you can do it.

And just because perl has More Than One Way To Do It (aka TIMTOWTDI), it doesn't mean you should do it this way.

*
*


07.07.17 6:05, sisyph...@optusnet.com.au пишет:

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

Reply via email to