I'd probably use a hash of hashes, with the outer hash keyed by the ticket id:

use strict; use warnings; my @fields = ( 'customer', 'status', 'priority', 'owner' ); my ( %HoH, $ticket ); while ( <DATA> ) { chomp; next if /^$/; # Better data validation recommended! if ( my @tmp = / ^(\S+): \s+\[([^\]]+)\] # square bracket, followed \s+\[([^\]]+)\] # by anything other than a \s+\[([^\]]+)\] # square bracket, followed \s+\[([^\]]+)\] # by a square bracket /x ) { $ticket = shift @tmp; $HoH{$ticket} = { map { $fields[$_] => $tmp[$_] } 0 .. $#tmp }; } else { s/^\s+//g; $HoH{$ticket}{comment} .= " $_"; } } foreach my $record ( keys %HoH ) { print "\n$record:\n"; print "$_ = $HoH{$record}{$_}\n" for keys %{ $HoH{$record} }; } __DATA__ fabx-t160: [ggurudut] [UNAN/OWNR] [C2] [kelrod] navicli chglun -l 3 -name "newname" doesn't work. Try a different name, retardo! fabx-t161: [dozone] [UNAN/OWNR] [C2] [dchoi] The GUI needs to hide the CPP SEs from the unimported list fabx-t162: [haurora] [UNAN/OWNR] [C1] [glade] Cisco hardware related bug :idprom error on cisco switch on loading + 0.1.5.5 salagent

(Code tested, but only on a limited data set)

However, YMMV.

dave


In reply to Re: parsing multi-line output from a cli command by Anonymous Monk
in thread parsing multi-line output from a cli command by TASdvlper

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.