privoxy-log-parser: Fix an 'uninitialized value' warning
authorFabian Keil <fk@fabiankeil.de>
Mon, 20 Feb 2017 15:57:40 +0000 (15:57 +0000)
committerFabian Keil <fk@fabiankeil.de>
Mon, 20 Feb 2017 15:57:40 +0000 (15:57 +0000)
... when generating statistics for a log file without response headers.

While privoxy-log-parser was supposed to detect this already,
the check was flawed and the message the user didn't see was
somewhat confusing anyway.

Now the message is less confusing, more helpful and actually printed.

Reported by: Robert Klemme

tools/privoxy-log-parser.pl

index 227d71e..d779d83 100755 (executable)
@@ -8,7 +8,7 @@
 #
 # https://www.fabiankeil.de/sourcecode/privoxy-log-parser/
 #
-# $Id: privoxy-log-parser.pl,v 1.162 2014/06/03 10:26:21 fabiankeil Exp $
+# $Id: privoxy-log-parser.pl,v 1.163 2016/08/26 11:19:53 fabiankeil Exp $
 #
 # TODO:
 #       - LOG_LEVEL_CGI, LOG_LEVEL_ERROR, LOG_LEVEL_WRITE content highlighting
@@ -2191,13 +2191,13 @@ sub print_stats () {
     # Due to log rotation we may not have a complete picture for all the requests
     printf "Improperly accounted requests: ~%d\n", abs($stats{requests} - $client_requests_checksum);
 
-    if ($stats{method} eq 0) {
-        print "No response lines parsed yet yet.\n";
-        return;
-    }
-    print "Method distribution:\n";
-    foreach my $method (sort {$stats{'method'}{$b} <=> $stats{'method'}{$a}} keys %{$stats{'method'}}) {
-        printf "%8d : %-8s\n", $stats{'method'}{$method}, $method;
+    if (exists $stats{method}) {
+        print "Method distribution:\n";
+        foreach my $method (sort {$stats{'method'}{$b} <=> $stats{'method'}{$a}} keys %{$stats{'method'}}) {
+            printf "%8d : %-8s\n", $stats{'method'}{$method}, $method;
+        }
+    } else {
+        print "Method distribution unknown. No response headers parsed yet. Is 'debug 8' enabled?\n";
     }
     print "Client HTTP versions:\n";
     foreach my $http_version (sort {$stats{'http-version'}{$b} <=> $stats{'http-version'}{$a}} keys %{$stats{'http-version'}}) {