If you want to assign some variables of a hash to an array. i.e you want to take some of the elements from hash based on there keys into a array here is a trick\
my %hash = (one => 'one', two => 'two', three => 'three');
my @array ;
@array = @{$hash}{'one','two'};
If you have a hashref and want to take the values of some keys into an array you can do the following.
my $hashref = {one => 'one', two => 'two', three => 'three'};
my @array ;
@array = @{%$hash}{'one','two'};
Thursday, October 30, 2008
How to take a hash slice.
Posted by Nexis at 1:53 AM
Labels: Data Structures
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment