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. We know tha $foo eq $bar forces $foo and $bar into string context and then compares them as strings, and $foo == $bar forces numeric context. I personally find this to be a hallmark of Perl, a way in which it Does What I Mean, where what I mean is indicated by the operator that I chose to use. Assignment like $result = !$i does not provide a context, but the negation operator does---boolean---and so we get a result that is boolean true or false, both of which are represented by special kinds of dual-vars, as was already explained. David -- "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." -- Brian Kernighan