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.open(IN,$log) || die $!, "\n";
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:
The key there being the '!~' operator.if ( $_ !~ m/$i/ ) { print; }
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
In reply to Re: Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
by dsb
in thread Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
by quasimojo321
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |