What if you want to preserve the @_ aliasing?
Um...Just use @_?
Say you can't because you're
using the rest of @_ for other parameters
(like another optional list).
Well if you find yourself in that improbable situation, you can use shift_list.
If there's other ways I'd like to know, this is a fishing expedition.sub routine { my $self = shift; my $list = &shift_list; # expose our @_ # then @_ = ($other, $args) s/a/A/g for (@$list); # change the original ... }
(That weird ( sub {\@_} )->($_[0]) stuff is stolen from Damian's slice aliasing code posted to perl6-lang)sub shift_list { # shift one element of @_ and return it as an array ref # PRESERVING the @_ aliasing # (if called like &shift_list we get the caller's actual @_) my $list; if(ref $_[0]) { $list = shift; unless (ref $list eq 'ARRAY') { die "Not an array ref ($list)"; } } else { # aliasing funkiness # pass aliased $_[0] to sub ref which returns a ref to it's @_ $list = ( sub {\@_} )->($_[0]); shift; # for parent } return $list; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Preserve @_ aliasing a (scalar||array)
by BrowserUk (Patriarch) on Jan 06, 2004 at 09:55 UTC |