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

Question about wantarray()

Expand Messages
  • Mystik Gotan
    I can t really figure out what the purpose of wantarray() is. Can someone please give me a good, decent explanation? Thanks in advance :-) ... Bob Erinkveld
    Message 1 of 5 , Nov 26, 2002
    • 0 Attachment
      I can't really figure out what the purpose of wantarray() is.
      Can someone please give me a good, decent explanation?

      Thanks in advance :-)


      --------------
      Bob Erinkveld (Webmaster Insane Hosts)
      www.insane-hosts.net
      MSN: gotan2k3@...




      _________________________________________________________________
      MSN Zoeken, voor duidelijke zoekresultaten!
      http://search.msn.nl/worldwide.asp
    • Hans Ginzel
      ... Probably someone can explain it better, but I know there were a good (IMHO) example in manpages. So I tried: bash$ echo /usr/share/perl*/*/pod bash$ cd
      Message 2 of 5 , Nov 26, 2002
      • 0 Attachment
        > I can't really figure out what the purpose of wantarray() is.
        > Can someone please give me a good, decent explanation?

        Probably someone can explain it better, but I know there were a
        good (IMHO) example in manpages. So I tried:

        bash$ echo /usr/share/perl*/*/pod
        bash$ cd <Esc>. # Press Escape and dot -- last parametr of previous line
        or
        bash$ cd `!!` # result of prev. command
        bash$ grep wantarray *

        and this line was it

        perlsub.pod: return wantarray ? @parms : $parms[0];

        so
        bash$ perldoc perlsub

        and on the approx. fourth page is example of sub uppercase with
        explanation.

        Regards
        Hans Ginzel

        --
        Fight against terrorism? What about users which are terrorised by Windows?
      • Jeff Eggen
        ... perldoc -f wantarray reveals: wantarray Returns true if the context of the currently executing subroutine is looking for a list value. Returns false if the
        Message 3 of 5 , Nov 26, 2002
        • 0 Attachment
          >>> gotan2k3@... 11/26/02 08:35am >>>
          >I can't really figure out what the purpose of wantarray() is.
          >Can someone please give me a good, decent explanation?

          >Thanks in advance :-)

          perldoc -f wantarray reveals:

          wantarray
          Returns true if the context of the currently
          executing subroutine is looking for a list value.
          Returns false if the context is looking for a
          scalar. Returns the undefined value if the context
          is looking for no value (void context).

          return unless defined wantarray; # don't bother
          doing more
          my @a = complex_calculation();
          return wantarray ? @a : "@a";

          This function should have been named wantlist()
          instead.

          I would interpret this as being something you put in a subroutine to
          determine what output is expected: list, scalar, or nothing.

          A quick search on google revealed a more complete example on this
          page:

          http://practicalperl.com/slides/L02/slide_057.html

          I'm assuming it's usage is correct ;-)

          Hope this helps,
        • prakash
          is there a unix command to print hardware information of the sever?? (not disk space .. like processor speedy and name.. all those..) or perl code.. (this is
          Message 4 of 5 , Dec 5, 2002
          • 0 Attachment
            is there a unix command to print hardware information of the sever??
            (not disk space .. like processor speedy and name.. all those..)
            or perl code.. (this is perl group ;-))

            -prak
          • hans@matfyz.cz
            ... You can read the /proc file system using perls I/O routines or output of some external commands: dmesg, uptime, uname -a,... H.
            Message 5 of 5 , Dec 6, 2002
            • 0 Attachment
              On Thu, Dec 05, 2002 at 12:10:46PM -0800, prakash wrote:
              > is there a unix command to print hardware information of the sever??
              > (not disk space .. like processor speedy and name.. all those..)
              > or perl code.. (this is perl group ;-))

              You can read the /proc file system using perls I/O routines or
              output of some external commands: dmesg, uptime, uname -a,...

              H.
            Your message has been successfully submitted and would be delivered to recipients shortly.