Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re (tilly) 4: Slurp a file

by tilly (Archbishop)
on Jan 08, 2001 at 22:52 UTC ( #50548=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: Slurp a file
in thread Slurp a file

That will be slower though.

The reason I suggested it is in case someone wanted to use your SuperSplit with tied filehandles. I would not depend on a tied filehandle correctly paying attention to $/, so the join makes sense.

But if you care about performance or have good reason to believe that people won't use tied filehandles, then avoid join.

Replies are listed 'Best First'.
(tye)Re3: Slurp a file
by tye (Sage) on Jan 08, 2001 at 22:55 UTC

    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")
      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)

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2023-01-28 07:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found