in reply to regex log file too many results
$get is somehow being reset; this can’t be happening in the code you show, so you must be omitting things from your script. Once it’s set to an empty string, that will result in an empty pattern, and an empty pattern means “reuse the last successfully matched pattern,” whatever that happens to be.
Note that you’re using printf like print. Don’t do that, it opens you up to format string vulnerabilities. In Perl, always use print unless you have a specific reason to prefer printf.
Also, you’re using foreach(<>). Basically, this is always a mistake. You want while(<>) instead. The two loops do nearly the same thing, with the salient difference being that foreach(<>) slurps the entire file into memory at once, whereas while(<>) only nibbles at it as it processes it.
open(FH, "$pd_zvkk") is problematic. You are using two-argument open without specifying a mode. If $pd_zvkk is user input or derived from it, someone could exploit the lack of explicit mode to overwrite stuff on your server. But even if you specify an explicit mode, two-argument open is problematic; use three-argument open. Also, a lone variable is quoted; that’s unnecessary, and while it’s no harm here other than adding useless noise to your code, in other contexts it will bite you. Don’t do that. So so far, you should write the expression like this: open( FH, '<', $pd_zvkk ). It’d be even better if instead of the global filehandle, you use a lexical one – open( my $fh, '<', $pd_zvkk ) and replace FH in the rest of the code with $fh – for all the reasons for which it is better to use lexical rather than global variables.
The double negation in unless($_ !~ /$get/) has been commented on.
Lastly, this is just a hunch, but your code smells like the typical CGI script written without strict and taint mode. If my hunch is right, you should really read Ovid’s excellent CGI course before you shoot yourself in the foot (or rather, someone else does it).
Makeshifts last the longest.
|
|---|