in reply to Speed reading (files)

With read, you are telling it how big the file is, so it can preallocate a buffer to that size and fill it in a single call to the system (even if the system chooses to break it into smaller reads from disk). So, one call to the system to allocate the memory. One call to perform the read.

With the traditional slurp, it doesn't know how big the file is, so it

  1. allocates a buffer (probably 4k),
  2. calls the systems to read 4k,
  3. checks to see if 4k was read,
    • if not, finished.
    • if so, reallocates the buffer to +4k (which probably means the first 4k gets copied).
  4. repeat from step 2.

Try using:

my $data = do{ local $/ = \( -s FILE ); <FILE> };;

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".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.