hello boleary
Just reiterating what has already been said, but have spent most of the day getting there.
I have been getting a bit deeper lately, and am just posting what is hopefully useful. If you value your sanity, you'll read just enough of Devel::Peek Examples to understand SV, IV, the difference between PVIV and PVNV and then get the hell out of there.
I'll save some trouble. On the top lines SV = means a scalar, which all of these are.
SV = PV means its a String
SV = IV means its an Integer
You can easily see the PV part that describes when the scalar values are strings, and they all have a trailing null, the backslash followed by a zero.
When the scalar values are Integers the IV part on the bottom line shows the value, that is not nul terminated.
#!perl use strict; use warnings; use feature qw/say/; use Devel::Peek; my @trailing_truth = ( "0", "0\n", 0, '0', '0'."\n" ); foreach my $zeroe ( @trailing_truth ){ warn $zeroe ? "true\n" : "false\n"; Dump $zeroe; # Dump defined $zeroe; # check the REFCNT! # Dump length $zeroe; # # Dump 0+$zeroe; # numeric coercion # Dump !!$zeroe; # boolean coercion # say "[][][][][][][][][][]\n"; print "\n"; }
output
false SV = PV(0x1e850c) at 0x1ea53c REFCNT = 2 FLAGS = (POK,pPOK) PV = 0x26b37bc "0"\0 CUR = 1 LEN = 12 true SV = PV(0x1e851c) at 0x1ea5cc REFCNT = 2 FLAGS = (POK,pPOK) PV = 0x26b381c "0\n"\0 CUR = 2 LEN = 12 false SV = IV(0x1ea618) at 0x1ea61c REFCNT = 2 FLAGS = (IOK,pIOK) IV = 0 false SV = PV(0x1e8534) at 0x1ea64c REFCNT = 2 FLAGS = (POK,pPOK) PV = 0x26b39dc "0"\0 CUR = 1 LEN = 12 true SV = PV(0x1e854c) at 0x1ea66c REFCNT = 2 FLAGS = (POK,pPOK) PV = 0x26b39fc "0\n"\0 CUR = 2 LEN = 12 Press any key to continue . . .
PVNV means its a double or float, this comes up on the return value from the defined builtin. The return value also shows that the scalar has both numeric and string values stored now.
The trick on this one is putting the conditional test before the Devel::Peek::Dump on there to help see what test the values relate to.
In reply to Re: methods for dealing with zero '0' as a string or char
by Don Coyote
in thread methods for dealing with zero '0' as a string or char
by boleary
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |