[Chicago-talk] Multi dimensional hash
Doug Bell
madcityzen at gmail.com
Sun Oct 11 14:09:24 PDT 2015
What you have there should work. You could also simplify it with loops or slices:
for my $name_key ( qw( FName LName Nickname ) ) {
$validtn_hash{ Name }{ $name_key } = $input_hash->{ $name_key };
}
# OR
$validtn_hash{ Name }{ $_ } = $input_hash->{ $_ } for qw( FName LName Nickname );
# OR
@{ $validtn_hash{ Name } }{qw( FName LName Nickname )} = @{ $input_hash }{qw( FName LName Nickname )};
Doug Bell
madcityzen at gmail.com
> On Oct 11, 2015, at 3:07 PM, richard at rushlogistics.com wrote:
>
> If I have the following hash reference:
>
> my $input_hash = {
>
> Hometown => 'Chicago',
> FName => 'Jim',
> LName => 'Brown',
> Nickname => 'Jimbo',
>
> };
>
> Is there a way that I can create a multimensional hash like they've done here http://perlmaven.com/multi-dimensional-hashes
>
> But instead have it structured with the input_hash's key name as one of the dimensions? So that I would have:
>
> $validtn_hash{class}{input_hash_key} = input_hash value; # where City and Name are examples of classes
>
> $validtn_hash{"City"}{Hometown} = $input_hash->{Hometown};
> $validtn_hash{"Name"}{FName} = $input_hash->{FName};
> $validtn_hash{"Name"}{LName} = $input_hash->{LName};
> $validtn_hash{"Name"}{Nickname} = $input_hash->{Nickname};
>
> Or is this even possible?
>
> Thanks
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
More information about the Chicago-talk
mailing list