in reply to regex log file too many results

First, what's with the double negation?

unless($_ !~ /$get/) { printf STDERR ("String = $_ \n"); }
can be written much more clearly as
if (m/$get/) { printf STDERR ("String = $_ \n"); }

And then it seems to me like you're setting $get to an empty string (or maybe a whitespace character) somewhere else in your code, because your logfile shows the program matching on that.

Hope that helps.

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan

Replies are listed 'Best First'.
Re^2: regex log file too many results
by minixman (Beadle) on Nov 14, 2005 at 10:41 UTC
    Thanks for the info, i did try that, and i think i found where the problem sort of is.

    This is a extract from a CGI program, so the web interface, reads a log file and parses the info back into html.
    So when i use the following code.
    #!/usr/bin/perl my $get = "Starting"; open(FH, "/home/cuthbe/programs/perlweb/PCAMWebStatus/log/pd_zvkk.log" +) || die ("Unable to open pd_zvkk log file : !$ \n"); printf ("My get = $get \n"); while(<FH>) { chomp(); #next if ($_ !~ /$get/); if($_ =~ m/$get/) { printf ("String found: \"$_\" : \n"); } $ perl test.pl My get = Starting String found: "Fri Aug 26 05:56:01 BST 2005 INFO: PD/ZVKK Load: Start +ing." : (cuthbe@ferrari)-(10:27 AM Mon Nov 14)-(cgi-bin) $
    It works perfectly, now this is on the command line.
    When i put this into the cgi code, and get it to read the log file."with replacing the log file for variable"
    open(FH, "$pd_zvkk") || die ("Unable to open pd_zvkk log file: $pd_ +zvkk : !$ \n"); printf STDERR ("My get = $get \n"); while(<FH>) { chomp(); #next if ($_ !~ /$get/); if(m/$get/) { printf STDERR ("String found: \"$_\" : \n"); } } <code> Then i get this in the apache error log.<br> <code> [Mon Nov 14 10:28:16 2005] [error] [client 10.142.204.242] My get = St +arting [Mon Nov 14 10:28:16 2005] [error] [client 10.142.204.242] String foun +d: "Fri Aug 26 05:56:01 BST 2005 INFO: PD/ZVKK Load: Starting." : [Mon Nov 14 10:28:16 2005] [error] [client 10.142.204.242] My get = [Mon Nov 14 10:28:16 2005] [error] [client 10.142.204.242] String foun +d: "Fri Aug 26 05:56:01 BST 2005 INFO: PD/ZVKK Load: Starting." : [Mon Nov 14 10:28:16 2005] [error] [client 10.142.204.242] String foun +d: "Fri Aug 26 05:56:01 BST 2005 INFO: PD/ZVKK Load: Removing old cl +ientacc files." : [Mon Nov 14 10:28:16 2005] [error] [client 10.142.204.242] String foun +d: "Fri Aug 26 05:56:01 BST 2005 INFO: PD/ZVKK Load: Running the sto +red proc." : [Mon Nov 14 10:28:16 2005] [error] [client 10.142.204.242] String foun +d: "" : [Mon Nov 14 10:28:16 2005] [error] [client 10.142.204.242] String foun +d: "PL/SQL procedure successfully completed." : [Mon Nov 14 10:28:16 2005] [error] [client 10.142.204.242] String foun +d: "" : [Mon Nov 14 10:28:16 2005] [error] [client 10.142.204.242] String foun +d: "could not open /dev/kbd to get keyboard type US keyboard assumed" + :

    So it seems like when running in a CGI env it reads and prints the whole log file, very strange.

      So it seems like when running in a CGI env it reads and prints the whole log file, very strange.

      I think you're wrong in your conclusion. Take a look through your CGI code. You're setting $get to a different value somewhere in there.


      Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan