[Chicago-talk] Multi dimensional hash

richard at rushlogistics.com richard at rushlogistics.com
Sun Oct 11 16:07:24 PDT 2015


Doug,
 
Thanks for the help. This got me where I need to go. 

On Sun, 11 Oct 2015 16:09:24 -0500, Doug Bell  wrote:

       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

_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20151011/50c5e37c/attachment-0001.html>


More information about the Chicago-talk mailing list