in reply to Testing for definition of references

if( defined $arrayref && defined @$arrayref )

should do it, but

if( defined $arrayref && ref( $arrayref ) eq 'ARRAY' )

looks better to me.

This will test if the array has elements:

if( @$arrayref )

Replies are listed 'Best First'.
Re: Re: Testing for definition of references
by DBX (Pilgrim) on Jun 26, 2003 at 18:09 UTC
    Thanks, but I actually am trying to avoid using ref() if possible. Also, you are testing:
    if(defined $arrayref)
    This is insufficient since $arrayref may be set to a scalar value and thus would return true. I don't want to test to see if $arrayref is simply defined, but if the array it references is defined. I use:
    if(defined @$arrayref)
    as a means to distinguish the definition of an array reference from all other types of data. My question relates to whether this is valid test or not.
      Why are you avoiding ref()?

      No, it's not. An empty array will return false!