in reply to creating hash of hashes from input file
#! perl -slw use strict; use Data::Dump qw[ pp ]; $Data::Dump::WIDTH = 50; $/ = ''; ## para mode; see Perlvar 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; __DATA__ FullName : User1 Home Address : 111 address lane Phone : 555-555-5555 FullName : User2 Home Address : 222 address lane 2 Phone : 777-777-7777
Produces:
c:\test>junk7 { User1 => { FullName => "User1", "Home Address" => "111 address lane", Phone => "555-555-5555", }, User2 => { FullName => "User2", "Home Address" => "222 address lane 2", Phone => "777-777-7777", }, }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: creating hash of hashes from input file
by xiaoyafeng (Deacon) on Jul 17, 2010 at 14:47 UTC | |
by BrowserUk (Patriarch) on Jul 17, 2010 at 15:37 UTC | |
by toolic (Bishop) on Jul 17, 2010 at 16:58 UTC | |
by BrowserUk (Patriarch) on Jul 17, 2010 at 22:34 UTC | |
by wfsp (Abbot) on Jul 18, 2010 at 08:03 UTC | |
by FunkyMonk (Bishop) on Jul 18, 2010 at 21:59 UTC | |
|
Re^2: creating hash of hashes from input file
by perlnewbie9292 (Novice) on Jul 17, 2010 at 15:21 UTC | |
by BrowserUk (Patriarch) on Jul 17, 2010 at 15:43 UTC | |
by perlnewbie9292 (Novice) on Jul 17, 2010 at 15:55 UTC |