Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing two array references.

Status
Not open for further replies.

LucL

Programmer
Joined
Jan 23, 2006
Messages
117
Location
US
Hi,

I'm trying to pass 2 arrays to a subroutine, but I wan't the subroutine to be able to manipulate the arrays directly (and not eat up memory recreating them).

How can I pass these 2 arrays to the subroutine. I know I have to pass them as a reference but I don't know what the sub should look like (as far as parameters) or whether i should pass as \@arr1 or @arr, etc.

I know that I can access the first array by looking at $_ in the sub but what would the second one be?

Simple example would work. Thanks guys!
 
You shoukd pass them link this
Code:
test( \@array_1, @array_2 );

sub test {
	my ( $arr1, $arr2 ) = @_;

	for my $item ($@arr1) { print $item . "\n"; }

	for my $item ($@arr2) { print $item . "\n"; }
}

M. Brooks
 
thanks M. Brooks!
 
probably just a typo, but this is missing a backslash:

test( \@array_1, @array_2 );

should be:

test( \@array_1, \@array_2 );
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top