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

Returning an array ref from function

Expand Messages
  • RAJESH PETHE
    Hi All, I m trying to return an array ref from a function like this -- my $return = {x = [$dtn], sign = $type }; push @{$return_ref}, $return;
    Message 1 of 5 , Feb 28, 2006
      Hi All,

      I'm trying to return an array ref from a function like this --

      my $return = {x => [$dtn],
      sign => $type };
      push @{$return_ref}, $return;
      return $return_ref;

      but I'm getting error from other part of the script that it's not an
      array ref. Please tell me the correct way to do it.
      Please note that all variables in the function above is lexical (my).

      Regards
      Rajesh


      ============================================================================================================================

      Tech Mahindra, formerly Mahindra-British Telecom.


      Disclaimer:


      The contents of this E-mail (including the contents of the enclosure(s) or attachment(s) if any) are privileged and confidential material of Tech Mahindra and should not be disclosed to, used by or copied in any manner by anyone other than the intended addressee(s). In case you are not the desired addressee, you should delete this message and/or re-direct it to the sender. The views expressed in this E-mail message (including the enclosure(s) or attachment(s) if any) are those of the individual sender, except where the sender expressly, and with authority, states them to be the views of Tech Mahindra.


      This e-mail message including attachment/(s), if any, is believed to be free of any virus. However, it is the responsibility of the recipient to ensure that it is virus free and Tech Mahindra is not responsible for any loss or damage arising in any way from its use.

      ============================================================================================================================

      [Non-text portions of this message have been removed]
    • Rob Richardson
      It looks to me like you re returning a hash reference, not an array reference. However, being far from an expert, I can t help you do what you want to do. I
      Message 2 of 5 , Feb 28, 2006
        It looks to me like you're returning a hash reference, not an array
        reference. However, being far from an expert, I can't help you do what you
        want to do.

        I am curious, though, to see the code that is trying to use this function,
        so that I can get an idea of how your code is using whatever it gets back
        from here.

        RobR


        [Non-text portions of this message have been removed]
      • merlyn@stonehenge.com
        ... RAJESH Hi All, RAJESH I m trying to return an array ref from a function like this -- RAJESH my $return = {x = [$dtn], RAJESH sign =
        Message 3 of 5 , Feb 28, 2006
          >>>>> "RAJESH" == RAJESH PETHE <rpethe@...> writes:

          RAJESH> Hi All,

          RAJESH> I'm trying to return an array ref from a function like this --

          RAJESH> my $return = {x => [$dtn],
          RAJESH> sign => $type };
          RAJESH> push @{$return_ref}, $return;
          RAJESH> return $return_ref;

          Is that the only thing in the array ref? If so, just return it
          via the anonymous array constructor:

          return [ { x => [$dtn], sign => $type } ];

          But I'm not sure why you want to return a reference to an array containing
          a single item, or why you want a hash to contain an array ref containing
          a single item either ($dtn). More explaining to do!

          --
          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!
        • RAJESH PETHE
          Actually I m trying to initialize a complex data structure from the return value of this function. The function is being called from an expression that is
          Message 4 of 5 , Feb 28, 2006
            Actually I'm trying to initialize a complex data structure from the
            return value of this function. The function is being called from an
            expression that is initializing a hash whose each key returns a
            reference to an array. So this is the arrayref that I'm looking to
            return from the function.

            Regards
            Rajesh

            -----Original Message-----
            From: perl-beginner@yahoogroups.com
            [mailto:perl-beginner@yahoogroups.com] On Behalf Of Rob Richardson
            Sent: Tuesday, February 28, 2006 9:08 PM
            To: perl-beginner@yahoogroups.com
            Subject: Re: [PBML] Returning an array ref from function

            It looks to me like you're returning a hash reference, not an array
            reference. However, being far from an expert, I can't help you do what
            you want to do.

            I am curious, though, to see the code that is trying to use this
            function, so that I can get an idea of how your code is using whatever
            it gets back from here.

            RobR


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



            Unsubscribing info is here:
            http://help.yahoo.com/help/us/groups/groups-32.html
            Yahoo! Groups Links








            ============================================================================================================================

            Tech Mahindra, formerly Mahindra-British Telecom.


            Disclaimer:


            The contents of this E-mail (including the contents of the enclosure(s) or attachment(s) if any) are privileged and confidential material of Tech Mahindra and should not be disclosed to, used by or copied in any manner by anyone other than the intended addressee(s). In case you are not the desired addressee, you should delete this message and/or re-direct it to the sender. The views expressed in this E-mail message (including the enclosure(s) or attachment(s) if any) are those of the individual sender, except where the sender expressly, and with authority, states them to be the views of Tech Mahindra.


            This e-mail message including attachment/(s), if any, is believed to be free of any virus. However, it is the responsibility of the recipient to ensure that it is virus free and Tech Mahindra is not responsible for any loss or damage arising in any way from its use.

            ============================================================================================================================
          • RAJESH PETHE
            I m trying to create this structure on the fly and the structure below is just an example. I want the return value to initialize another complex hash which
            Message 5 of 5 , Mar 1, 2006
              I'm trying to create this structure on the fly and the structure below
              is just an example. I want the return value to initialize another
              complex hash which takes a reference to an array as value.

              I'm calling the functions as --

              %hash = (
              'type' => &functionname ,
              ....
              );

              But it's not working this way. I need to call the function
              \&functionname rather than &functionname. Please help.

              Regards
              Rajesh

              -----Original Message-----
              From: Randal L. Schwartz [mailto:merlyn@...]
              Sent: Tuesday, February 28, 2006 9:33 PM
              To: RAJESH PETHE
              Cc: perl-beginner@yahoogroups.com
              Subject: Re: [PBML] Returning an array ref from function

              >>>>> "RAJESH" == RAJESH PETHE <rpethe@...> writes:

              RAJESH> Hi All,

              RAJESH> I'm trying to return an array ref from a function like this --

              RAJESH> my $return = {x => [$dtn],
              RAJESH> sign => $type };
              RAJESH> push @{$return_ref}, $return;
              RAJESH> return $return_ref;

              Is that the only thing in the array ref? If so, just return it via the
              anonymous array constructor:

              return [ { x => [$dtn], sign => $type } ];

              But I'm not sure why you want to return a reference to an array
              containing a single item, or why you want a hash to contain an array ref
              containing a single item either ($dtn). More explaining to do!

              --
              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!

              ============================================================================================================================

              Tech Mahindra, formerly Mahindra-British Telecom.


              Disclaimer:


              The contents of this E-mail (including the contents of the enclosure(s) or attachment(s) if any) are privileged and confidential material of Tech Mahindra and should not be disclosed to, used by or copied in any manner by anyone other than the intended addressee(s). In case you are not the desired addressee, you should delete this message and/or re-direct it to the sender. The views expressed in this E-mail message (including the enclosure(s) or attachment(s) if any) are those of the individual sender, except where the sender expressly, and with authority, states them to be the views of Tech Mahindra.


              This e-mail message including attachment/(s), if any, is believed to be free of any virus. However, it is the responsibility of the recipient to ensure that it is virus free and Tech Mahindra is not responsible for any loss or damage arising in any way from its use.

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