Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TeeJay (2309)

TeeJay
  (email not shown publicly)
http://www.aarontrevena.co.uk/

Working in Truro
Graduate with BSc (Hons) in Computer Systems and Networks
pm : london.pm, bath.pm, devoncornwall.pm
lug : Devon & Cornwall LUG
CPAN : TEEJAY [cpan.org]
irc : TeeJay
skype : hashbangperl
livejournal : hashbangperl [livejournal.com]
flickr :hashbangperl [flickr.com]

Journal of TeeJay (2309)

Friday May 21, 2004
09:40 AM

slices and references

[ #18871 ]
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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.