You can always try the ref() command to figure out whether the variable you are dealing with is an array, a hash, or a scalar. Of course, this method works on a reference to the actual variable. Say like this:
my %hash = (foo => bar);
my @arr = (1);
my $var = \%hash;
my $var1 = \@arr;
my $var2 = 2;
print ref $var;
print ref $var1;
print ref $var2;
Will print:
HASH
ARRAY
* the last line is '' for 'not reference'.
I'm not sure if you really want to go any further from this and actually attempt to determin whether a variable is a string or an integer (or float). For that you could use regular expressions..
my $num = 15;
if ($num =~ /^[+-]?\d+$/) {
print "Dealing with an integer\n";
}
You could also play around with other forms of the match to distinct between float and integer values. However, in many cases when anyone has to go as far as to having to determine precise type of a variable, there's a big chance his/her code is wrong.
|
"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith
|