Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Ingy needed a pure Perl method of determining if a scalar contained an integer or a string
While his results are cool, he could have saved a lot of work if he'd asked around to see if anyone had already found a solution to this problem (note the unary "~", it's important)
sub is_integer { ~$_[0] !~ /\D/ }
Here are some tests to demonstrate that it works:
#!/usr/bin/perl -wT use strict; use Test; BEGIN { plan tests => 345 } for my $num (-56789, -300, -1, 0..100, 5345, 6574572, 23457356) { ok( is_integer($num) ); my $string = "$num"; ok( not is_integer($string) ); } for my $string ((map { chr($_) } 0..127), 'dog', 'cat', 'mouse') { ok( not is_integer($string) ); } sub is_integer { ~$_[0] !~ /\D/ }
I found the is_integer() implementation in my cool-snippets-from-perlmonks directory, but can't seem to find the original thread.....

-Blake


In reply to Re3: Pure Perl Internals (with Pure Perl Segfaults) by blakem
in thread Pure Perl Internals (with Pure Perl Segfaults) by Ovid

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2014-07-24 03:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (156 votes), past polls