Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: How can you sysread an entire file?

by ikegami (Pope)
on Jan 13, 2006 at 22:14 UTC ( #523101=note: print w/ replies, xml ) Need Help??


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

my $string = do { local $/; <FILEHANDLE> };
looks nicer than
my $string; { local $/; $string = <FILEHANDLE> }
but takes twice as much memory. That's probably not that wise when dealing with entire files.


Comment on Re^3: How can you sysread an entire file?
Select or Download Code
Re^4: How can you sysread an entire file?
by BrowserUk (Pope) on Jan 13, 2006 at 22:54 UTC
    takes twice as much memory.

    Do you have some evidence of that as it appears to make no difference at all on my system?

    Update: I take that back. It does double the memory usage.


    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.
Re^4: How can you sysread an entire file?
by BrowserUk (Pope) on Jan 13, 2006 at 23:15 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://523101]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2015-07-07 08:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls