{
    "content": [
        {
            "type": "text",
            "text": "# SCALAR (perldoc)\n\n## Sections\n\n- **Found in /usr/share/perl/5.34/pod/perlfaq4.pod**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "SCALAR",
        "section": "-q",
        "mode": "perldoc",
        "summary": null,
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "Found in /usr/share/perl/5.34/pod/perlfaq4.pod",
                "lines": 55,
                "subsections": []
            }
        ],
        "sections": {
            "Found in /usr/share/perl/5.34/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": []
            }
        }
    }
}