Loading ...
Sorry, an error occurred while loading the content.

24716Re: [PBML] Counting elements of Array

Expand Messages
  • Marcos Onisto
    Dec 15, 2006
    • 0 Attachment
      Hello All,

      I'm so sorry. I read about it in somewhere that I dont remember. I only ask you because I cant find it on the context. I'm really sorry.

      The len is exactly what i need.

      Thanks a lot,

      Marcos


      Jenda Krynicky <Jenda@...> wrote: From: Marcos Onisto <mlonisto@...>
      > How can I count the elements of one array? I'm using the push
      > function, but this is return message like below.
      >
      > -bash-3.00$ ./checksrvs.pl
      > Useless use of push with no values at ./checksrvs.pl line 68.

      push() is used to add elements to arrays, not for getting their
      length or anything.

      There is one important and unusual concept in Perl that you simply
      have to learn and understand. Context. Expressions return different
      values based on the context! Please try to read up on context in your
      book or some docs.

      Eg. in case of arrays, if the list context the value of an array is
      the list of its elements, in scalar context it's the length of the
      array:

      my @a = (1,2,3);
      my @b = (4,5);

      my @c = (@a, @b); # list context
      my @copy = @a; # list context as well

      print "\@c = (@c)\n";

      my $len = @a; # scalar context
      print "\$len=$len\n";

      HTH, Jenda

      ===== Jenda@... === http://Jenda.Krynicky.cz =====
      When it comes to wine, women and song, wizards are allowed
      to get drunk and croon as much as they like.
      -- Terry Pratchett in Sourcery





      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around
      http://mail.yahoo.com

      [Non-text portions of this message have been removed]
    • Show all 7 messages in this topic