Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: cat vs. file handle speed?

by Adam (Vicar)
on Mar 30, 2001 at 06:06 UTC ( #68263=note: print w/replies, xml ) Need Help??


in reply to cat vs. file handle speed?

Think about the overhead involved. Here is my brief analysis:
open(INFILE,"cat textfile |") while(<INFILE>) {...}
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,"textfile") while(<INFILE>) {...}
Perl opens a file handle directly to the file. No other processes are started.
system("cat textfile | filter.pl")
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.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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://68263]
help
Chatterbox?
[1nickt]: stevieb it's just a simple web page with a POST form. You can set the attribute so when the user's browser opens a file manager to select a file to upload, it will only show those o f the type you want to get.
[1nickt]: Question for my learned friends: is there a word meaning "CSV-like" i.e. I want to say that I accept CSV files, but the separator doesn;t have to be a comma. Or is that implicit these days?
[chacham]: dsv
[chacham]: dsv

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-07-22 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (340 votes). Check out past polls.