in reply to reference to an array slice?
Or if you're in feeling devious then TheDamian illustrates how alias an array slice in this perl6-language post in perl5 :>{ package Tie::Array::Slice; use Tie::Array; @ISA = 'Tie::StdArray'; use Data::Dumper; use strict; sub FETCH { ${ $_[0]->[ $_[1] ] } } sub STORE { ref $_[2] ? $_[0]->[ $_[1] ] = $_[2] : ${ $_[0]->[ $_[1] ] } = $_[2]; } } use strict; my @a = qw/ one two three four /; tie my @b, 'Tie::Array::Slice'; @b = (\(@a))[1 .. 2]; print "\$b[1]: $b[1]\n"; print "\$a[2]: $a[2]\n"; print "before \@a: @a\n"; $b[0] = 'xxx'; print "after \@a: @a\n"; __output__ $b[1]: three $a[2]: three before @a: one two three four after @a: one xxx three four
_________
broquaint
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: reference to an array slice?
by BrowserUk (Patriarch) on Sep 26, 2003 at 11:37 UTC |