Data Transfer Report for

Period Device Code Port Code Traffic Direction Data Transfer (GB)
#### use strict; use warnings; use 5.010; use HTML::Template; use Data::Dumper; my @lines = ( "Bobby June abc 15 north good", "Bobby Sept xyz 20 north fair", "Bobby March xyz 10 north great", "Jenny July def 30 south poor", "Jenny Aug stu 20 south bad", ); my @inner_loop_fields = qw{ lastmonth_period device port direction usage }; my %combined_info_for; #key = customer name #value = array for (@lines) { my($name, @data) = split; my %field_info_for; @field_info_for{@inner_loop_fields} = @data; #assignment to hash slice--allows you to do a mass #assignment to multiple keys at once push @{$combined_info_for{$name}}, \%field_info_for; #add hashes to the customer array--one array for each #customer name, perl magic -> if array doesn't exist, #create an empty one and push the value into the array } #say Dumper(%combined_info_for); #check your work my @outer_loop_fields = qw{ cust_name billfix_loop }; my @outer_loop_info; while ( my($name, $AoH_ref) = each %combined_info_for ) { my %hash_for; @hash_for{@outer_loop_fields} = ($name, $AoH_ref); #assignment to a hash slice again--multiple keys in the hash #are assigned to in one step push @outer_loop_info, \%hash_for; } my $template = HTML::Template->new(filename => "html2.tmpl"); $template->param(custname_loop => \@outer_loop_info); print $template->output();