Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining a variable type 1

Status
Not open for further replies.

Nebbish

Programmer
Apr 7, 2004
73
US
Hey all, variable question that I'm sure has been asked before in some form: how do I determine what type a variable is? I'm passing a subroutine arrays and strings, but I don't know how many strings or how many arrays, nor do I know what order they're coming in. So, I have:

Code:
sub sample {
	my $var;
	while($var = shift) {
		if(array($var)) {
			foreach my $i (@{$var}) {
				print "is array:", $var[$i], "\n";	
			}
		} else {
			print $var, "\n";
		}
	}
}

I'm looking for something that does what I hoped array($var) would do above.

-Nick
 
Check the 'ref' operator, it will return the variable type HASH,HASHREF,SCALAR or ARRAY usually.
 
way to go siberian :) I looked for that for ages.

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top