Larry meticulously copied all features
Not quite: (quoting perlvar) "Remember: the value of $/ is a string, not a regex. awk has to be better for something."
There is also a broader (information-theoretic?) issue where Awk can, in some cases, be more concise because it is less powerful than Perl.
I could easily translate this given awk script in a one2one fashion to Perl, by encapsulating the open on demand into a short sub.
You probably could, but the Awk script had one other feature that might be some extra code in Perl: Awk's FNR is reset at the beginning of each input file, so that script will correctly process multiple input files given on the command line, extracting the header from each file.
On the other hand, it also accumulates open files, so if you have enough distinct columns across a multi-file input set, you will run out of file descriptors. :-)
To make it matter we need start a script over and over again.
In the case of a one-liner simple enough to be replaced using sed in a shell script, we were talking about running it over and over again. The better answer is usually to rewrite the entire script in Perl, but sometimes a shell script is the right tool for the job, if the job consists almost entirely of running external programs with very little "local" data processing.
In reply to Re^8: Split tab-separated file into separate files, based on column name (open on demand)
by jcb
in thread Split tab-separated file into separate files, based on column name
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |