First of all, you are not opening the file right. Try:
open(IN,$log) || die $!, "\n";
Always have an '|| die' when you are opening a file. If the file fails to open and you continue anyway, you'll eventually get an error for trying to work on a closed filehandle, and your script will die anyway.
Second of all, you seem to using '$_' correctly so I wouldn't worry about that.
However in order to get a non-match you would need to use the expression:
if ( $_ !~ m/$i/ ) {
print;
}
The key there being the '!~' operator.
Update: I've been advised to not use the '|| die' notation and use instead 'or die'. As far as I can see this has to do with the trouble that could be caused by combining this notation with a function call that does not use parentheses.
The higher precedence of '||' causes Perl to see the call differently than if the 'or die' notation was used(when making a function call sans parentheses). Example:
open FH, "filename" or die $!;
#will read as its meant to: open(FH,"filename") or die $!;
open FH, "filename" || die $!;
#will read as: open FH,("filename" || die $!); which is not good since
+ the only time
#this expression will be treated as false is in cases where filename i
+s an undefined expression(0,"",or undefined scalar)
#but unrecognized file names will not be evaluated as false so the die
+ will serve no purpose and the the script will continue to run
Amel - f.k.a. - kel |