in reply to Re^2: creating hash of hashes from input file
in thread creating hash of hashes from input file

#! perl -slw use strict; use Data::Dump qw[ pp ]; $Data::Dump::WIDTH = 50; $/ = ''; my %hash; while( <DATA> ) { my %subhash; for my $line ( split "\n" ) { my( $key, $value ) = split /\s+:\s+/, $line; $subhash{ $key } = $value; } $hash{ $subhash{ FullName } } = \%subhash; } ##pp \%hash; for my $primaryKey ( keys %hash ) { print "$primaryKey:"; for my $subKey ( keys %{ $hash{ $primaryKey } } ) { print "\t$subKey => $hash{ $primaryKey }{ $subKey }"; } } __DATA__ FullName : User1 Home Address : 111 address lane Phone : 555-555-5555 FullName : User2 Home Address : 222 address lane 2 Phone : 777-777-7777

Gives:

c:\test>junk7 User1: Phone => 555-555-5555 Home Address => 111 address lane FullName => User1 User2: Phone => 777-777-7777 Home Address => 222 address lane 2 FullName => User2

Replies are listed 'Best First'.
Re^4: creating hash of hashes from input file
by perlnewbie9292 (Novice) on Jul 17, 2010 at 15:55 UTC
    Thanks just figured it out right before your post that I needed nested loops to actually get the data out. Thanks for the tips, I think need to play around more with hashes to get a better understanding. Thanks again for the quick responses. :)