in reply to How do I read an entire file into a variable?

Be careful with things like join("",<HANDLE>); If you have thousands of consecutive newlines, perl has to first create the array and then join it. That can get expensive. Do benchmarking. But I like something simillar to the following:
my $buf=$content=''; $content.=$buf while read(HANDLE,$buf,8192);
8192 is arbitrary so optimize with glee.

Replies are listed 'Best First'.
Re: Re: How do I read an entire file into a variable?
by TeeHee (Acolyte) on Dec 18, 2001 at 02:03 UTC
    The simple thought of reading a whole file (read: HD => BIG) into a variable (read: RAM => small) is pretty expensive by itself..
    of course i get your point of it being even more expensive when you also need to use processing time to join it after clogging your ram..

    (btw, my first post ;-} )
    (sorry if i sounded harsh..)