[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Thingies



At 09.55 -0400 1999.04.23, jacobs@azstarnet.com wrote:
>ok -- so if I'm going to have a series of arrays, each a different
>size, each of which may or may not have contents, I'm better off doing
>
>	defined ( $array1[0] )
>	defined ( $array2[0] )
>
>given that I'm going to be filling each array from the start. (It's just
>the end points that are variable.)

Probably.  It depends on what you want to know.  For instance, if you want
to make sure that $array[0] is defined, is an arrayref, and has at least
one element:

  if (defined $array[0] && ref $array[0] &&
      ref $array[0] eq 'ARRAY' && @$array[0]) {
    # ...
  }

Note that the extra 'ref $array[0]' is simply to quiet -w, because if you
do "ref $array[0] eq 'ARRAY'" and ref $array[0] is undef, you'll get a
warning.

If you just want to make sure $array[0] is defined, a simple
defined($array[0]) will suffice.  However, if you know for sure that each
element @array will be defined, that it will be an arrayref, etc., then
there is no need to check anything at all.


>Sorry if I'm being dense, but I want to make sure I'm understanding
>what you're saying. I'll do a `man perlfunc | grep defined` too...

Note that on Unix you can do `perldoc -f defined` to get that entry.  If
you ran splitman on perlfunc.1, you can do `man -s 3pl defined` or
somesuch, too.

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org