in reply to scalar variable or array reference test
ref returns the type being referenced, or false if it is not a refernce (you see empty string when we try to use it as a string):
use strict; use warnings; my $a = 123; my $aref = \$a; my @b = (1,2,3); my $bref = \@b; print "[" . ref($a) . "]\n"; print "[" . ref($aref) . "]\n"; print "[" . ref($b) . "]\n"; print "[" . ref($bref) . "]\n";
You can also use UNIVERSAL->isa():
use strict; use warnings; my $a = 123; my $aref = \$a; my @b = (1,2,3); my $bref = \@b; print UNIVERSAL::isa($aref, "SCALAR") + 0, "\n"; print UNIVERSAL::isa($bref, "ARRAY") + 0, "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: scalar variable or array reference test
by antirice (Priest) on Dec 13, 2003 at 21:12 UTC |