in reply to What type are you? Mr Hash, Sir Array, or Miss Scalar?

Doraemon,
There is a way to tell a variable's type by using defined() bla,bla,bla? That is news to me.

I am going to assume you mean some variable seen by your program that comes externally. If it was your own code you would only need to look at the sigil ( % => hash, $ => scalar, @ => array). If that is the case then you could probably get away with using ref (see perldoc -f ref). There are certainly limitations in ref, but I think it will fit your immediate needs.

Cheers - L~R
  • Comment on Re: What type are you? Mr Hash, Sir Array, or Miss Scalar?

Replies are listed 'Best First'.
Re: Re: What type are you? Mr Hash, Sir Array, or Miss Scalar?
by Doraemon (Beadle) on May 12, 2004 at 15:48 UTC
    defined() bla,bla,bla? yeah, right!
    Just a silly joke. Never seriously thought about that (harhar)
    But i've tried the ref, and it works just fine...problem solved

      ref is correct, however you can do it yourself if you want to .. (don't know why you would) you can

      my %test = ('test1'=>'value', 'test2'=>'value'); my $hash_ref = \%test; print "hash ref" if($hash_ref =~ m{HASH});
      I used that once(before I knew about ref). I don't know if that's horribly bad practice or not, but it works. So basically you could go to the trouble (again I don't know why you would want to) of setting up your own ref via a case statement of regex's