in reply to Re: Complex hash?
in thread Complex hash?

if (ref($hash{$_}) eq 'ARRAY')

I dont understand this.. Does the word 'ARRAY' have a special meaning in this context? What more such special words are there, and where is it possible to read about this? Appearently it does not work to write 'array' in lc.

Replies are listed 'Best First'.
Re^3: Complex hash?
by imp (Priest) on Aug 24, 2006 at 22:36 UTC
    The reason that 'array' doesn't match is that you are comparing the return value of ref with the string 'array'. ref returns what sort of reference something is, and in the case of arrays that string is 'ARRAY'

    See ref for more information.

Re^3: Complex hash?
by perlfan (Parson) on Aug 24, 2006 at 23:38 UTC
    ref returns the following values:
    • SCALAR
    • ARRAY
    • HASH
    • CODE
    • REF
    • GLOB
    • LVALUE
    And it those that you must test for - depending on what you are looking for.

      Just to disambiguate a little: ref returns SCALAR for a reference to a scalar. For a simple scalar it returns undef.

      Note too that ref returns the object type for an object so the range of strings that can be returned is essentially unlimited.


      DWIM is Perl's answer to Gödel