{
    "mode": "perldoc",
    "parameter": "SCALAR",
    "section": "-q",
    "url": "https://www.chedong.com/phpMan.php/perldoc/SCALAR/json",
    "generated": "2026-11-29T04:10:05Z",
    "sections": {
        "Found in /usr/share/perl/5.38/pod/perlfaq4.pod": {
            "content": "How do I determine whether a scalar is a number/whole/integer/float?\nAssuming that you don't care about IEEE notations like \"NaN\" or\n\"Infinity\", you probably just want to use a regular expression (see also\nperlretut and perlre):\n\nuse 5.010;\n\nif ( /\\D/ )\n{ say \"\\thas nondigits\"; }\nif ( /^\\d+\\z/ )\n{ say \"\\tis a whole number\"; }\nif ( /^-?\\d+\\z/ )\n{ say \"\\tis an integer\"; }\nif ( /^[+-]?\\d+\\z/ )\n{ say \"\\tis a +/- integer\"; }\nif ( /^-?(?:\\d+\\.?|\\.\\d)\\d*\\z/ )\n{ say \"\\tis a real number\"; }\nif ( /^[+-]?(?=\\.?\\d)\\d*\\.?\\d*(?:e[+-]?\\d+)?\\z/i )\n{ say \"\\tis a C float\" }\n\nThere are also some commonly used modules for the task. Scalar::Util\n(distributed with 5.8) provides access to perl's internal function\n\"lookslikenumber\" for determining whether a variable looks like a\nnumber. Data::Types exports functions that validate data types using\nboth the above and other regular expressions. Thirdly, there is\nRegexp::Common which has regular expressions to match various types of\nnumbers. Those three modules are available from the CPAN.\n\nIf you're on a POSIX system, Perl supports the \"POSIX::strtod\" function\nfor converting strings to doubles (and also \"POSIX::strtol\" for longs).\nIts semantics are somewhat cumbersome, so here's a \"getnum\" wrapper\nfunction for more convenient access. This function takes a string and\nreturns the number it found, or \"undef\" for input that isn't a C float.\nThe \"isnumeric\" function is a front end to \"getnum\" if you just want to\nsay, \"Is this a float?\"\n\nsub getnum {\nuse POSIX qw(strtod);\nmy $str = shift;\n$str =~ s/^\\s+//;\n$str =~ s/\\s+$//;\n$! = 0;\nmy($num, $unparsed) = strtod($str);\nif (($str eq '') || ($unparsed != 0) || $!) {\nreturn undef;\n}\nelse {\nreturn $num;\n}\n}\n\nsub isnumeric { defined getnum($[0]) }\n\nOr you could check out the String::Scanf module on the CPAN instead.\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}