in reply to Extracting a list of keys from a multi-dimensional hash.

I'm going on the assumption that you don't want the keys to be assigned to a list, but rather you want the hash values for a particular month to be assigned to the list. I haven't bothered sorting the result as you can sort the list however you want once it is assigned.

#!/usr/bin/perl use warnings; use strict; my %ManagerInCharge = ( 200610 => { 1 => "jane", 2 => "john", 3 => "joe", 4 => "frank", }, 200701 => { 1 => "gunder", 2 => "abel", 3 => "frank", }, ); my $month = "200701"; # # If you need the keys assigned, then the statement # my @slice = keys %{$ManagerInCharge{$month}} # is enough. # my @slice = map { $ManagerInCharge{$month}{$_} } ( keys %{$ManagerInCharge{$month}} ); for (@slice) { print "value is $_\n"; }
and the results are:

C:\Code>perl assign_slice.pl value is gunder value is frank value is abel

Replies are listed 'Best First'.
Re^2: Extracting a list of keys from a multi-dimensional hash.
by Anonymous Monk on Jan 16, 2008 at 19:15 UTC
    couldn't the statement:

    my @slice = map { $ManagerInCharge{$month}{$_} } ( keys %{$ManagerInCharge{$month}} );

    be written more simply as:

    my @slice = values %{$ManagerInCharge{$month}};