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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|