in reply to Passing references to array slices
I don't know what you're really trying to do, but I foresee two possible scenarios:
Pass a reference to a new array containing copies of the scalars in the slice. It's simple and clear:
$ perl my @a = qw/a b c d e/; sub printthese { local $, = ', '; print @{$_[0]}; print "\n"; } printthese( [ @a[0, 2, 4] ]); ^D a, c, e
Pass a reference to a new array containing aliases to the scalars in the slice, so you can modify them
$ perl my @a = qw/1 2 3 4 5/; sub zerothese { $_ = 0 for @{$_[0]}; } zerothese( &{sub {\@_}} (@a[0, 2, 4]) ); print join ', ', @a; print "\n"; ^D 0, 2, 0, 4, 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Passing references to array slices
by Anonymous Monk on Mar 18, 2004 at 10:52 UTC |