perl does not consider '09' to be a number

Perl does consider the string "09" to be a number, 0 + "09" == 9. The only question is, does the OP want this to be interpreted as an octal, which in this case would be invalid, or not.

$ perl -wMstrict -le 'print 77' 77 $ perl -wMstrict -le 'print 077 ' 63 $ perl -wMstrict -le 'print 0 + "077"' 77 $ perl -wMstrict -le 'print oct "077"' 63 $ perl -wMstrict -le 'print eval " 77"' 77 $ perl -wMstrict -le 'print eval "077"' 63
if (looks_like_number($$var)) { print "$$var is not a number\n";

You've got mistake in your logic there. Also note that looks_like_number tells you whether the string will properly auto-convert to a number (0+$str), but does not cover all of the numeric literals that Perl accepts in its source code, i.e. what eval will parse, such as 0b1001 or 1234_56; strings like "0b1001" won't automagically convert to numbers. I wrote about this a bit more at Re^3: why are hex values not numbers?


In reply to Re^2: Please help me understand string eval better by haukex
in thread Please help me understand string eval better by perltux

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.