in reply to Re^2: Printing the length of an array ?
in thread Printing the length of an array ?

Correct!

Better, and clearer, to write for line 7:

my $count = $#array; print "number of elements is " . ++$count . "\n";

Replies are listed 'Best First'.
Re^4: Printing the length of an array ?
by chromatic (Archbishop) on Mar 30, 2008 at 21:57 UTC

    That can be wrong for at least one very bad reason that you should be glad you don't know. This code is always correct, shorter, and less noisy:

    my $count = @array;
      That can be wrong for at least one very bad reason that you should be glad you don't know.

      That's so chromatic... and, of course, it does induce a post asking: what bad reason?

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        what bad reason?
        $[ = 42;
      oooooh, but i want to know