ukryule has asked for the wisdom of the Perl Monks concerning the following question:

I'm calling a method which returns an array of 'things' - which could be references or scalars (text). Is there a 'is_scalar' or 'is_reference' function? I want to do something like this:
@children = $h->content_list; foreach $c (@children) { if (is_scalar($c)) { print "$c\n"; } else { $c->do_something(); } }
(Incidentally my problem is parsing an HTML::Element object)

Replies are listed 'Best First'.
Re: How do you identify a reference?
by belg4mit (Prior) on May 09, 2002 at 04:34 UTC
    ref, returns some kind of true if it's a reference, specific values of truth for specific kinds of references.
Re: How do you identify a reference?
by dsb (Chaplain) on May 09, 2002 at 17:38 UTC
    use strict; my $var = "whatever"; # try different values to see what happens my $val = ref $var; my $res = $val ? "Is a Refenence: $val" : "Not a reference"; print $res, "\n";
    ref will return the type of reference(SCALAR,ARRAY,HASH,etc).




    Amel
    This is my cool %SIG