in reply to How can I test for the representation of an integer?

Thanks to Autobox you can do
use autobox::universal qw(type); say type("42"); # STRING say type(42); # INTEGER say type(42.0); # FLOAT say type(undef); # UNDEF
See chocolateboy's response in "How to tell apart numeric scalars and string scalars in Perl?"

Replies are listed 'Best First'.
Re^2: How can I test for the representation of an integer?
by sm@sh (Acolyte) on Apr 25, 2016 at 14:18 UTC
    Thanks - that's probably the most accessible way I've seen.
    Feels like it should be in Scalar::Util.
      Feels like it should be in Scalar::Util

      I don't think I would trust Scalar::Util to not fiddle about with the wrapping.
      For example, Scalar::Util's looks_like_number() returns true for a Math::BigInt object, even though the looks_like_number() XS function would return false.

      Cheers,
      Rob
Re^2: How can I test for the representation of an integer?
by Dave Burton (Initiate) on Nov 25, 2020 at 13:14 UTC
    Thank you, very useful! I ended up with this:
    if (eval {require autobox::universal;}) { autobox::universal->import('type'); } else { print 'Warning: Cannot locate autobox/universal.pm in @INC (you may + need to install autobox)' . "\n" . "In Strawberry Perl you can get autobox like this:\n" . " 1. from a Windows Administrator (elevated) command prompt +...\n" . " 2. cd \\strawberry\\perl\\bin\n" . " 3. cpan autobox::universal\n\n"; eval("sub type { return '?';}"); }