6/1 Writing a hash/array/scalar traversing function. How do I tell
if a variable passed to me is a hash, scalar, or array
in Perl? Thanks.
\_ You can't, unfortunately. If you really want to do that, you
have to pass a reference instead. --mconst
\_ Ah I got it. I need to dereference a variable, then
do a ref($var) to see its type. THANKS SO MUCH mconst.
\_ Guessing that you really mean you were passed a reference, call ref()
on it, which will give you undef (it was just a scalar), 'ARRAY',
'HASH', 'SCALAR', etc, meaning it was a reference to one of those.
--dbushong
\_ Welcome to perl, the worst of all typing worlds
\_ How about PHP, where the only way to find out if something is
an array or a hash is heuristically (i.e. "are the first few
keys ordered ints starting from 0?")
\_ And to be fair, ruby does some amazingly annoying things
with arrays as return values.
\_ Really? Like what? I've always found ruby's behavior
w.r.t. arrays to be as convenient as possible while still
completely flexible. --dbushong |