http://www.perlmonks.org?node_id=1170305

voltas has asked for the wisdom of the Perl Monks concerning the following question:

I have a working code that reads a log file and produces output like below:
=> [ 'Testing { ', 'JIRA' => 'COM-6789 ', 'Program' => 'Testing ', 'rev' => 'r876391 ', 'Reviewer' => 'Balise Mat ' 'Description' => 'Audited }, { ', 'Program' => 'Testing ', 'rev' => 'r698392 ', 'Reviewer' => 'Chan Joe ', 'JIRA' => 'COM-6789 ' 'Description' => 'SO hwat }, { ', 'JIRA' => 'COM-6789 ', 'Reviewer' => 'Chan Joe ', 'Program' => 'Testing ', 'rev' => 'r327896 ' 'Description' => 'Paid the Due } ], ' => [ 'Development { ', 'JIRA' => 'COM-1234 ', 'Reviewer' => 'John Wick ', 'rev' => 'r345676 ', 'Program' => 'Development ' 'Description' => 'Genral fix }, { ', 'Program' => 'Development ', 'rev' => 'r909276 ', 'Reviewer' => 'None ', 'JIRA' => 'COM-1234 ' 'Description' => 'Updating Received } ],
I want to print my output like Hash of Hash of Arrays, i.e. take Development as my first hash with the JIRA ID as the values and JIRA ID as the 2nd hash and the associated values. Example :
'Development { COM-1234 { ', 'JIRA' => 'COM-1234 ', 'Reviewer' => 'John Wick ', 'rev' => 'r345676 ', 'Program' => 'Development ' 'Description' => 'Genral fix }, { ', 'Program' => 'Development ', 'rev' => 'r909276 ', 'Reviewer' => 'None ', 'JIRA' => 'COM-1234 ' 'Description' => 'Updating Received } }, ],
Code snippet:
#!/usr/bin/perl use strict; use warnings; use 5.010; use Data::Dumper; my @records = do { local $/ = '------------------------------------------'; <>; }; chomp @records; my %jira; foreach (@records) { next unless /\S/; my %rec = /^(\w+):\s*(.+?)$/mg; push @{$jira{$rec{JIRA}}}, \%rec; } say Dumper \%jira; my %prog foreach (@records) { next unless /\S/; my %rec = /^(\w+):\s*(.+?)$/mg; push @{$jira{$rec{Program}}}, \%rec; } say Dumper \%prog;