On Thu, 2005-11-24 at 11:18 -0600, The Ghost wrote:
> Is there a way I can know if a variable ($hash{someKey}) is an array  
> or an arrayref or hashref or scalar?
> I could use eval, but I thought I remember there was some other  
> function for doing this.

>From the third edition of "Programming Perl"
(http://www.unix.org.ua/orelly/perl/prog3/ch29_02.htm):

>         ref EXPR
>         ref
> The ref operator returns a true value if EXPR is a reference, false
> otherwise. The value returned depends on the type of thing the
> reference refers to. Built-in types include: 
>         SCALAR
>         ARRAY
>         HASH
>         CODE
>         GLOB
>         REF
>         LVALUE
>         IO::Handle
> If the referenced object has been blessed into a package, then that
> package name is returned instead. You can think of ref as a "typeof"
> operator. 
>         if (ref($r) eq "HASH") {
>             print "r is a reference to a hash.\n";
>         }
>         elsif (ref($r) eq "Hump") {    # Naughty--see below.
>             print "r is a reference to a Hump object.\n";
>         }
>         elsif (not ref $r) {
>             print "r is not a reference at all.\n";
>         }

Eric P.
Sunnyvale, CA


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to