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();
|