slices and references

TeeJay on 2004-05-21T14:40:30

right I think I have sussed slices and references, so I'll put in this blog for safe keeping.

from #london.pm:
<aef> Hmm, I'm sure I can remember doing that. Now, exactly how...
<aef> perl -e '$x = [0,1,2,3,4,5]; print @$x[2,3]'
<aef> (assigning to the slice with the same syntax works)

so I try..

perl -e ' my $array = [qw(aaa bbbb ccc ddd ee ffff ggg hhhhh)]; @$array[2..3] = (qw(ccc1 ddd2)); print @$array;'
which returns..
aaabbbbccc1ddd2eeffffggghhhhhh

great!

then googling to perlmonks I came across..

my @slice = @$hashref{ qw(a d) };

ace!

see also perldoc perllol