A
Anno Siegel
Larry said:So it's better to to research little-known options to "cut" to process
multi-line input, so that Perl can fork off a "cut" process to do
things that can be done easily in Perl itself.
"Little known" is in the eye of the beholder. Opening a pipe to (or from)
a command is a standard Perl technique.
I'm taking exception with your apodictic "It forks a process for every
line...", which is simply not true. I said nothing about "better".
What had been done wrong (and not by me, by the way) was calling an
external Unix utility inside a loop. The increase was achieved by
translating the functionality into Perl to avoid calling the utility.
So?
So instead of fixing 1 line perfectly good Perl script, so that it uses
a Perl construct instead of calling out to an external Unix utility, I
should rewrite the whole thing in C? Just because I don't want an
external utility forked off inside a loop, that means "speed is an
issue" and so I shouldn't even be using Perl? That makes no sense.
What are you going on about?
If someone does something dumb, like calling an external program in
a tight loop, there are usually several ways to fix it. If the
external program can run the whole loop in one go, that would usually
be fastest (but benchmark, if it matters!). If speed is not important,
but style is, re-writing the loop in Perl would be preferred.
My point is that you can get the Perl script to run a lot faster by
avoiding calling external utilities like "cut" and instead using the
language features provided by Perl itself, especially inside a loop.
In other cases you can make a Perl script much faster by replacing
a Perl-only operation by a specialized external program. (Try beating
grep in Perl some day.) And the big assumption is "if speed is an issue".
Most of the time it isn't.
Anno