[clug] Thursday afternoon Perl/bash golf time
Andrew Janke
a.janke at gmail.com
Thu Jun 11 00:26:19 MDT 2015
I have a perl script, one of its jobs is to concatenate a large number
of (binary) files together.
I cheat and use the shell
# create rawfile
@args = ('cat', @catfiles, '>', "$opt{'tmpdir'}/all.raw");
&do_cmd(join(' ', @args));
(from: http://git.io/vIM2p)
Of course now someone tried to use it with a large number of input
files and it failed. So what to do?
1) for($i=0; $i<$#catfiles; $i+=100){
system("cat @catfiles[$i..$i+99] /tmp/cat-$i");
}
# cat the bits.
2) Do it in bash
for i in infiles.txt; do cat $i >> result; done
3) Do it in perl
4) Something far more clever.
Suggestions welcome, my brain is slowing.
ta
a
More information about the linux
mailing list