This opens a type of file handle commonly known as a pipe. It spawns an additional process, complete with a duplicate set of environment variables and memory management requirements. The OS must now swap memory back and forth between Perl and cat.open(INFILE,"cat textfile |") while(<INFILE>) {...}
Perl opens a file handle directly to the file. No other processes are started.open(INFILE,"textfile") while(<INFILE>) {...}
Perl invokes the shell which invokes cat and another instance of Perl! Plus the shell still has to open a file handle for the output of cat / the input to filter.plsystem("cat textfile | filter.pl")
Result: All three methods require a filehandle (aka a fileno, or a file descriptor) and two of the methods have the additional overhead of multiple processes. Use the second method and avoid all that.
In reply to Re: cat vs. file handle speed?
by Adam
in thread cat vs. file handle speed?
by dorpus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |