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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.