5 ms·
Very good article. Using perl instead of shell seems a lot more meaningful after this reading. cat * > ../collection becomes perl -e 'map{open ($f,"<",$_);pri
by webreac 14y ago
Very good article. Using perl instead of shell seems a lot more meaningful after this reading.
cat * > ../collection becomes
perl -e 'map{open ($f,"<",$_);print <$f>;close($f)}<*>' > ../collection
Strangely, it is far easier to write a correct script in perl than in shell.
- ralph 14y agoWhat's wrong with cat -- * >../foo given that cat(1posix) does support --.
- darkstalker 14y agoyou can also do it using system() with list arguments: perl -e 'system("cat", $_) for(<*>)' > ../collection
- mrud 14y agoWhat about perl -ne 'print;' -- * > ../collection
- kahirsch 14y agoThat's actually vulnerable to certain problems. Using "-n" or "-p" or "while (<>)", the files get opened using the 2-argument version of open, so a file names, e.g. "|rm *" can cause problems!