I'd create a state machine to parse the file. The state ($section in the below code) tells me what the parser expects to find. I also need to store the current zone and cluster to be able to attach the new information to the correct part of the structure.
#!/usr/bin/perl use warnings; use strict; my %zone; my $section = 0; my ($current_zone, $current_cluster); while (<>) { if (! $section) { if (/^Zone ID/) { $section = 'zones'; } elsif (/^Cluster ID/) { $section = 'clusters'; } elsif (/^Host Name/) { $section = 'hosts'; } elsif (my ($name) = /^(\S+)$/) { if (exists $zone{$name}) { $current_zone = $name; } elsif (exists $zone{$current_zone}{cluster}{$name}) { $current_cluster = $name; } } } elsif ('zones' eq $section) { if (my ($id, $name) = /(\S+)\s+(\S+)/) { $zone{$name}{id} = $id; } elsif (/^$/) { $section = 0; } } elsif ('clusters' eq $section) { if (my ($id, $name, $type, $mem, $cpu) = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/ ) { $zone{$current_zone}{cluster}{$name} = { id => $id, type => $type, mem => $mem, cpu => $cpu }; } elsif (/^$/) { $section = 0; } } elsif ('hosts' eq $section) { if (my ($host, $vms, $status, $state) = /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/ ) { $zone{$current_zone}{cluster}{$current_cluster}{host}{$hos +t} = { vms => $vms, status => $status, state => $state }; } elsif (/^$/) { $section = 0; } } } use Data::Dumper; print Dumper \%zone;
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

In reply to Re: Generate Hash of hashes by reading a large Input file by choroba
in thread Generate Hash of hashes by reading a large Input file by pr33

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.