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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |