in reply to Determine type of variable

The type of variable (scalar, array, or hash), is typically determined by the sigil attached to the front of the variable name ($,@, and %, respectively). However, if you're looking for traditional data types like int, float, char, etc, you need to start using regular expresssions to determine that. Perl's type system is based around data structures, not data types.

As a side note, if you're not sure what data type a variable is, you probably have a deeper programming issue that you should probably look at. Typically it should be obvious what data type you're dealing with. For example, if you are using a C-style for loop, you probably have an integer.

for ( my $i = 0; $i < 10; $i++ ) { # do stuff }

However, the nifty thing about the above snippet is this: it doesn't matter what data type $i is. Yes, there are cases where this is important, but most of the time, Perl allows you to focus on the actual problem you're trying to solve (how can I import this banking data?) instead of focusing on the minutia (should this be a short or a long?). This is a big win with Perl, but it's a tough concept for many to get used to.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.