in reply to Need advice in for perl use as awk replacement
This is an example where you should rewrite the entire shell script in Perl. Using Perl one-liners in shell scripts is asking for performance problems — perl's startup and shutdown overhead is negligible in an interactive context, but it can add up fast if you are running perl repeatedly for every line of input. Even Awk has a similar issue, where efficient programming requires sending a stream into Awk and reading either a brief summary or a stream of output back.
To better understand Perl's implicit loops, try B::Deparse, used via O:
$ perl -MO=Deparse -n -e 'print $_' LINE: while (defined($_ = <ARGV>)) { print $_; } -e syntax OK
You should have the full line in $_ unless your code changes $_. As other monks have mentioned, you will need to copy the regex capture variables somewhere to preserve them, or take advantage of the fact that regex matches in list context return the subexpressions: my @fields = m/$line_regex/; note that matching against $_ is implicit in Perl if you do not use the =~ operator.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Need advice in for perl use as awk replacement
by eyepopslikeamosquito (Bishop) on Sep 23, 2020 at 20:12 UTC |