Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

(tye)Re3: Slurp a file

by tye (Sage)
on Jan 08, 2001 at 22:55 UTC ( #50550=note: print w/replies, xml ) Need Help??


in reply to Re (tilly) 4: Slurp a file
in thread Slurp a file

For the best of both worlds, use both:

my $contents= do { local($/); join '', <INPUT> };
should work quickly for file handles that pay attention to $/ and work about as quickly as possible for those that don't.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re3: Slurp a file
by jeroenes (Priest) on Jan 08, 2001 at 23:04 UTC
    Modified davorg's code accordingly. Some improvement, clearly:
    Benchmark: timing 50000 iterations of hybrid, join, slash... hybrid: 4 secs ( 2.90 usr 0.38 sys = 3.28 cpu) join: 6 secs ( 5.65 usr 0.35 sys = 6.00 cpu) slash: 3 secs ( 1.95 usr 0.38 sys = 2.33 cpu)
    Cheers,

    Jeroen
    I was dreaming of guitarnotes that would irritate an executive kind of guy (FZ)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2021-05-17 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (158 votes). Check out past polls.

    Notices?