in reply to Re^3: Don't treat your numbers as strings, or Interpolation is worse than you might think
in thread Don't treat your numbers as strings, or Interpolation is worse than you might think

It's a really interesting meditation, thanks !

it left me with one question :
when you type :
print "ARRAY: @ary2\n"; # IV -> PVIV
it converts your IV to PVIV.

But, I would have thinked then that this :
$_ += 0 foreach @ary2;
executed on a PVIV, would keep it a PVIV. Why does it reverse it to an IV. It's a kind of rule internally ? When you make a numeric operation on a scalar, it convert it into an IV ? I mean, if there is a type which carry both (PVIV), it could have continue with it ? No ? Are there reasons other than the idea of using less memory/less timecode ?

Thanks,
Marsel
  • Comment on Re^4: Don't treat your numbers as strings, or Interpolation is worse than you might think
  • Select or Download Code

Replies are listed 'Best First'.
Re^5: Don't treat your numbers as strings, or Interpolation is worse than you might think
by Joost (Canon) on Jul 23, 2006 at 13:21 UTC
      The effect of removing this flag is very interesting—the value of the string stored in the variable is not deleted, but is "considered" incorrect and is not copied to new variables :)
      perl -MDevel::Peek -e'$x = 3; qq($x); $x+=1; Dump $x; $y=$x; Dump $y' SV = PVIV(0x15d75f4) at 0x15d57e4 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 4 PV = 0x1a53acc "3"\0 CUR = 1 LEN = 2 SV = PVIV(0x15d7604) at 0x15d64d4 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 4 PV = 0
      You see—the PV (value of the string) for $x was not updated by the numeric operation and was not copied to $y. So, being strict, the variables after numification become not pure IV, but PVIV storing only integer, looking much like simple IV, which causes much less work to copy :)

           s;;Just-me-not-h-Ni-m-P-Ni-lm-I-ar-O-Ni;;tr?IerONim-?HAcker ?d;print