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' => '' } };

In reply to Re: Hash creation problem by kevbot
in thread Hash creation problem by agentorange

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.