On Wed, Jul 27, 2005 at 03:43:19PM -0700, Piotr Fusik wrote:
> The result of the unary minus operator, when applied to
> an undefined value (e.g. undefined variable) is unexpected:
> 
> perl -le 'print for -0,-"",-0.0,-undef'
> 0
> 0
> -0
> -0
> 
> In my opinion, -undef should be identical to -"", i.e. 0, not -0.0.

I'd say -0 but same end result.  -0 and -undef should probably produce the
same thing.

$ perl -MDevel::Peek -wle 'print Dump -undef' 
Use of uninitialized value in negation (-) at -e line 1.
SV = NV(0x80de00) at 0x801270
  REFCNT = 1
  FLAGS = (PADTMP,NOK,pNOK)
  NV = -0

$ perl -MDevel::Peek -wle 'print Dump -0'SV = IV(0x80b520) at 0x801270
  REFCNT = 1
  FLAGS = (PADBUSY,PADTMP,IOK,READONLY,pIOK)
  IV = 0

Not that it really makes much difference but its curious why undef is being
numerified as an NV.


-- 
Michael G Schwern     [EMAIL PROTECTED]     http://www.pobox.com/~schwern
Reality is that which, when you stop believing in it, doesn't go away.
        -- Phillip K. Dick

Reply via email to