From 1b48202e28b5000e1a9904cef82bc436b3628c94 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Tue, 6 Jan 2015 11:40:46 +0000 Subject: [PATCH] Bug 13522: Make it explicit that scalar containd a hash ref Prior to perl 5.12 keys can only operate on a hash. So although $data[0] ( thats an abysmal variable name! ) will contain a hash ref the perl compiler cannot deduce that from the context and gives a syntax error. Add the hash sigil to make the context explicit and the compiler can generate the correct code. Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall Signed-off-by: Mason James --- tools/viewlog.pl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/viewlog.pl b/tools/viewlog.pl index 1fbd6be100..d2bd1c900e 100755 --- a/tools/viewlog.pl +++ b/tools/viewlog.pl @@ -171,6 +171,29 @@ if ($do_it) { output_html_with_http_headers $input, $cookie, $template->output; } else { # Printing to a csv file + my $content = q{}; + my $delimiter = C4::Context->preference('delimiter') || ','; + if (@data) { + my $csv = Text::CSV::Encoded->new( { encoding_out => 'utf8', sep_char => $delimiter } ); + $csv or die "Text::CSV::Encoded->new FAILED: " . Text::CSV::Encoded->error_diag(); + + # First line with heading + # Exporting bd id seems useless + my @headings = grep { $_ ne 'action_id' } sort keys %{$data[0]}; + if ( $csv->combine(@headings) ) { + $content .= $csv->string() . "\n"; + } + + # Lines of logs + foreach my $line (@data) { + my @cells = map { $line->{$_} } @headings; + if ( $csv->combine(@cells) ) { + $content .= $csv->string() . "\n"; + } + } + } + + # Output print $input->header( -type => 'text/csv', -attachment => "$basename.csv", -- 2.20.1