First let me make sure I understand your question correctly, since it is not very clear what exactly you are looking for.( Posting some code would have helped.)

You have code of the type

use strict; use warnings; use vars( @list0, @list1, @list2 ); sub DoSomething() { my( @localList0, @localList1, @localList2); #do something here my( @tempList ) = ( \@localList0, \@localList1, \@localList2 ); return @tempList; } #main program my @tempList = DoSomething(); push @list0, @$tempList[0]; push @list1, @$tempList[1]; push @list2, @$tempList[2];

Assuming above (or something similar) is what you are looking at improving, I would suggest passing in references to the array into the subroutine. The subroutine can then push stuff onto the right arrays without the need of temporary arrays.

use strict; use warnings; use vars( @list0, @list1, @list2 ); sub DoSomething( \@ \@ \@ ) { my( $listRef0, $listRef1, $listRef2) = @_; #do something here push @$listRef0, somelist; push @$listRef1, somelist; push @$listRef2, somelist; } #main program DoSomething( \list0, \list1, \list2 );
The other, less preferred option would be to directly refer to the outer arrays from within the subroutine. Depending on the size of your program this might be clearer, especially if your script needs to be maintained by someone not familiar with perl style references. However, if the subroutine will be in a separate module, you want to avoid doing this at all costs.
use strict; use warnings; use vars( @list0, @list1, @list2 ); sub DoSomething() { #do something here push @list0, somelist; push @list1, somelist; push @list2, somelist; } #main program DoSomething();

In reply to Re: Returning arrays to a push statement by data64
in thread Returning arrays to a push statement by rq-2102

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.