blueflashlight has asked for the wisdom of the Perl Monks concerning the following question:
I want to read in this file, split each line on the ":", and store the values in a hash like ...IMNSearch.msg.en_US.rte.com:IMNSearch.msg.en_US.rte.com:2.4.0.0: : :C: + :Text Search Messages - U.S. English: : : : : : :1:0: IMNSearch.rte:IMNSearch.rte.com:2.4.0.0: : :C: :Text Search Client/Ser +ver Shared Files : : : : : : :1:0: IMNSearch.rte.httpdlite:IMNSearch.rte.httpdlite:2.1.0.0: : :C: :Lite N +etQuestion Local Web Server: : : : : : :1:0:
I think I've got this part working fine; the problem comes in when I try to print the output. What I wind up with is ...$data{"foo"}{IMNSearch.msg.en_US.rte.com} = 2.4.0.0
Here is what I've got ...IMNSearch.msg.en_US.rte.com IMNSearch.msg.en_US.rte.com IMNSearch.rte IMNSearch.rte IMNSearch.rte.httpdlite IMNSearch.rte.httpdlite
Am I missing something obvious, or doing something dumb (or both?)my (%data, $system, @fields); $system = "foo"; open (FILE, "$system"); while (<FILE>) { @fields = split (/:/, $_); $data{$system}{$fields[$1]} = $fields[$2]; }; close FILE; foreach (sort keys %{$data{$system}}) { printf ("%-30s%-30s\n", $_, $data{$system}{$_}); };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with printing values from a hash of hashes
by xdg (Monsignor) on Mar 31, 2006 at 02:26 UTC | |
by blueflashlight (Pilgrim) on Mar 31, 2006 at 02:41 UTC | |
|
Re: Help with printing values from a hash of hashes
by roboticus (Chancellor) on Mar 31, 2006 at 02:35 UTC | |
|
Re: Help with printing values from a hash of hashes
by BrowserUk (Patriarch) on Mar 31, 2006 at 02:26 UTC | |
by xdg (Monsignor) on Mar 31, 2006 at 02:28 UTC | |
by BrowserUk (Patriarch) on Mar 31, 2006 at 03:02 UTC |