http://www.perlmonks.org?node_id=523109


in reply to Re^3: How can you sysread an entire file?
in thread How can you sysread an entire file?

I think I made an interesting discovery. As you suggest above, if I do this it only makes one copy of the file in memory:

P:\test>perl -le" my $s; do{ local $/; $s=<>}; print length $s; system qq[tasklist /fi \"pid eq $$\" ]" 1000000.dat 11000001 Image Name PID Session Name Session# Mem Usag +e ========================= ====== ================ ======== =========== += perl.exe 604 0 12,860 +K

And if I do it this way it uses two copies:

P:\test>perl -le" my $s=do{ local $/; <>}; print length $s; system qq[tasklist /fi \"pid eq $$\" ]" 1000000.dat 11000001 Image Name PID Session Name Session# Mem Usag +e ========================= ====== ================ ======== =========== += perl.exe 1372 0 23,624 +K

But what fooled me, as I was using my perl shell, is that if you eval the statement, only one copy is made:

P:\test>perl -le" my $s = eval q[do{ local $/; <>}]; print length $s; system qq[tasklist /fi \"pid eq $$\" ]" 1000000.dat 11000001 Image Name PID Session Name Session# Mem Usag +e ========================= ====== ================ ======== =========== += perl.exe 1764 0 12,880 +K

And I can't quite figure out why that should be so?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.