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

Re: [PBML] Counting elements of Array

Expand Messages
  • Marcos Onisto
    Hello All, I forgot to say how I use the push: my $rel = ; $rel = push(@report); Thanks all, Marcos Marcos Onisto wrote:
    Message 1 of 7 , Dec 14, 2006
    • 0 Attachment
      Hello All,

      I forgot to say how I use the push:

      my $rel = "";
      $rel = push(@report);

      Thanks all,

      Marcos


      Marcos Onisto <mlonisto@...> wrote: Hello All,

      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.

      I really appreciate some help,

      Thanks a lot,

      Marcos

      ---------------------------------
      Everyone is raving about the all-new Yahoo! Mail beta.

      [Non-text portions of this message have been removed]






      ---------------------------------
      Any questions? Get answers on any topic at Yahoo! Answers. Try it now.

      [Non-text portions of this message have been removed]
    • merlyn@stonehenge.com
      ... Marcos Hello All, Marcos I forgot to say how I use the push: Marcos my $rel = ; Marcos $rel = push(@report); push isn t documented to return anything
      Message 2 of 7 , Dec 14, 2006
      • 0 Attachment
        >>>>> "Marcos" == Marcos Onisto <mlonisto@...> writes:

        Marcos> Hello All,
        Marcos> I forgot to say how I use the push:

        Marcos> my $rel = "";
        Marcos> $rel = push(@report);

        push isn't documented to return anything useful. And you're pushing
        nothing anyway.

        Maybe you meant:

        push @report, $rel;

        If you did, please be very careful in the future when you post a message.
        Every character counts. :)
        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      • Jenda Krynicky
        From: Marcos Onisto ... push() is used to add elements to arrays, not for getting their length or anything. There is one important and
        Message 3 of 7 , Dec 14, 2006
        • 0 Attachment
          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
        • Marcos Onisto
          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
          Message 4 of 7 , 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]
          • Jenda Krynicky
            From: Marcos Onisto ... No need to apologize, sorry if my post came across that way. Perl context is something that does need some getting
            Message 5 of 7 , Dec 15, 2006
            • 0 Attachment
              From: Marcos Onisto <mlonisto@...>
              > 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.

              No need to apologize, sorry if my post came across that way.

              Perl context is something that does need some getting used to,
              there's nothing wrong with asking.

              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
            Your message has been successfully submitted and would be delivered to recipients shortly.