in reply to reference question
Here's two samples:
Note that when we pass by value, we have to pass back the array as a return value. When we pass by ref, we're modifying the array in the caller's space.my @files = qw( foo bar bat ); @files = byvalue( @files ); byreference( \@files ); sub add_txt_by_value { my @array = @_; foreach ( @array ) { $_ .= ".txt"; } return @array; } sub add_txt_by_reference { my $arrayref = shift; foreach ( @$arrayref ) { $_ .= ".txt"; } }
Updated: s/$array/$arrayref/ in the second example. Thanks, Hofmator.
xoxo,
Andy
--
<megaphone>
Throw down the gun and tiara and come out of the float!
</megaphone>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: reference question
by Hofmator (Curate) on Aug 14, 2001 at 19:57 UTC |