perl

How do I tell what type of value is in a Perl variable?


How do I tell what type of value is in a Perl variable?

$x might be a scalar, a ref to an array or a ref to a hash (or maybe other things).


Solution

  • ref():

    Perl provides the ref() function so that you can check the reference type before dereferencing a reference...

    By using the ref() function you can protect program code that dereferences variables from producing errors when the wrong type of reference is used...