In addition to the other advice, Perl makes possible neat idioms that I find are quite readable (adding ! to a regex match, while sometimes useful, can help you get lost in a sea of symbols):
while (<IN>) { # print if /$pattern/; # normal "grep" print unless /$pattern/; # grep -v }
$_ is the "default" argument to print, as well as to the pattern match. The "grep -v" line is equivalent to:
print $_ unless $_ =~ /$pattern/;
HTH
perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
In reply to Re: Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
by arturo
in thread Unix 'grep -v' equivalency in Perl (was: Perl Regex Question)
by quasimojo321
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |