I had some fun with numeric keys, then explored the surprising string 8 is NOT eq number 8, not realizing until much later the cause of this result: if ($string_eight eq $b).

After all, $string_eight and $numeric_eight are 'eq'. And, as I expected, the 'eq' operator causes stringification of the numeric value.

use strict; use warnings; use Data::Dumper; use Devel::Peek; my %hash = ( 1e2 => '100', 100 => '100', 0x64 => '100', 0144 => '100', ); print Dumper(\%hash); my $string_eight = '8'; my $numeric_eight = 8; print "\n\$numeric_eight before use with 'eq'\n"; Dump($numeric_eight); if ($string_eight eq $numeric_eight) { print "'eq'\n"; } else { print "not 'eq'\n"; } print "\n\$numeric_eight after use with 'eq'\n"; Dump($numeric_eight); print "\n\$numeric_eight = $numeric_eight\n"; print "\n\$numeric_eight after use in a string (i.e. stringification)\ +n"; Dump($numeric_eight); if ($string_eight eq $numeric_eight) { print "not 'eq'\n"; } else { print "'eq'\n"; } print "\n\$string_eight then \$numeric_eight after all\n"; Dump($string_eight); Dump($numeric_eight); __END__ $VAR1 = { '100' => '100' }; $numeric_eight before use with 'eq' SV = IV(0x97df82c) at 0x97df830 REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = 8 'eq' $numeric_eight after use with 'eq' SV = PVIV(0x97e01b8) at 0x97df830 REFCNT = 1 FLAGS = (PADMY,IOK,POK,pIOK,pPOK) <-- note POK is now set IV = 8 PV = 0x97ee168 "8"\0 <-- and there is now a PV, CUR + and LEN as well as IV CUR = 1 LEN = 4 $numeric_eight = 8 $numeric_eight after use in a string (i.e. stringification) SV = PVIV(0x97e01b8) at 0x97df830 REFCNT = 1 FLAGS = (PADMY,IOK,POK,pIOK,pPOK) IV = 8 PV = 0x97ee168 "8"\0 CUR = 1 LEN = 4 not 'eq' $string_eight then $numeric_eight after all SV = PV(0x98339d8) at 0x98736e8 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x97e4ba0 "8"\0 CUR = 1 LEN = 4 SV = PVIV(0x97e01b8) at 0x97df830 REFCNT = 1 FLAGS = (PADMY,IOK,POK,pIOK,pPOK) IV = 8 PV = 0x97ee168 "8"\0 CUR = 1 LEN = 4

In reply to Re^3: Illegal octal digit error by ig
in thread Illegal octal digit error by lakshmananindia

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.