in reply to TIMTOWTDI Challenge: Open a file
The big advantage of this method shows up when you want to deal with large files with a Perl that doesn't understand them, while cat does. (In that case opening the file directly only lets you read the first 2 GB, while opening it this way allows you to fetch through the whole file.)open(FILE, "cat $file |") or die "Cannot read '$file': $!";
I helped a number of people with this trick back in the day, but its time has is long past now. Today you can compile Perl to understand how to handle large files (which you couldn't easily do with, say, Perl 5.004), and this setting is on by default.
The disadvantages are numerous. You require an extra process, you have to worry about escaping special characters in the filename, error handling is more complex, etc, etc, etc. The only remaining advantage that I can think of for this method is that the additional parallelism might allow you to reduce the effect of disk latency if you were doing simple processing of a large file off of a slow disk. But that should only make a big difference if I/O time was close to processing time, and I'd need to see a benchmark before I'd believe it really was helping.
|
|---|