in reply to Hash creation problem
Others have given you good suggestions already. I just wanted to show that you could use the Text::xSV::Slurp module to create the HoH structure for you. The whitespace separated data would be a problem for this module, so you would need your input data to be in a delimited format for this approach to work (like csv shown below). BrowserUK has shown how to deal with the whitespace separated data that you have. I would encourage you to become very familiar with how to use hashes in perl before resorting to a module to do the work for you, since they are such an important feature of perl.
This code:
#!/usr/bin/env perl use strict; use warnings; use Text::xSV::Slurp; my $hoh = xsv_slurp( \*DATA, shape => 'hoh', key => 'Subsystem', ); use Data::Dumper; print Dumper $hoh; exit; __DATA__ Subsystem,Group,PID,Status inetd,tcpip,2424886,active xntpd,tcpip,3473550,active rwhod,tcpip,,inoperative snmpd,tcpip,,inoperative aixmibd,tcpip,,inoperative hostmibd,tcpip,,inoperative snmpmibd,tcpip,,inoperative
Gives the output:
$VAR1 = { 'inetd' => { 'Group' => 'tcpip', 'Status' => 'active', 'PID' => '2424886' }, 'hostmibd' => { 'Group' => 'tcpip', 'Status' => 'inoperative', 'PID' => '' }, 'snmpmibd' => { 'Status' => 'inoperative', 'PID' => '', 'Group' => 'tcpip' }, 'aixmibd' => { 'PID' => '', 'Status' => 'inoperative', 'Group' => 'tcpip' }, 'snmpd' => { 'Group' => 'tcpip', 'Status' => 'inoperative', 'PID' => '' }, 'xntpd' => { 'Group' => 'tcpip', 'Status' => 'active', 'PID' => '3473550' }, 'rwhod' => { 'Group' => 'tcpip', 'Status' => 'inoperative', 'PID' => '' } };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Hash creation problem
by BrowserUk (Patriarch) on Feb 19, 2014 at 16:20 UTC | |
by kevbot (Vicar) on Feb 19, 2014 at 16:28 UTC | |
by agentorange (Sexton) on Feb 20, 2014 at 11:11 UTC |