perl-like "slurp" in PHP?

From: gm (me_at_here.com)
Date: 12/23/04


Date: Wed, 22 Dec 2004 22:46:20 -0500

There is a module for perl called "slurp" which (from the documentation)
'serves one purpose - to provide a simple means to read (or slurp) an
entire file into memory for processing. This module allows the
replacement of the prototypical foreach- or while- loops used for
opening and reading of files with single-line constructs.'

In its simplest use, it can read a file (everything in unix is a "file"
of strings, webpages, socket output, everything) into an array, one line
at a time into one array element.

I often use it to suck an entire webpage into an array and iterate
through the contents while in memory. I've seen routines to suck a file
into a string, so something similar will probably work for an array but
does anyone know if there's a function or class for PHP that already
does this?



Relevant Pages

  • Re: perl-like "slurp" in PHP?
    ... > entire file into memory for processing. ... > of strings, webpages, socket output, everything) into an array, one line ... > at a time into one array element. ... I've seen routines to suck a file ...
    (comp.lang.php)
  • Re: Recursively filter an array
    ... providing the Big O Notation or a benchmark. ... The run order was array, while, slurp. ... slurp => sub { ...
    (perl.beginners)
  • Re: REGEXP removing - il- - -b-f and - il- - - - f
    ... > Is there any good reason to slurp the entire file into memory? ... I have plenty of system memory, ... >want to use the array in scalar context: ... > In the end I want the F01 column and the % column. ...
    (perl.beginners)
  • Re: Slurp large files into an array, first is quick, rest are slow
    ... > I am slurping a series of large .csv files directly into an array ... The first time I slurp a file it is ... The second time I do it the slurping is very slow ...
    (comp.lang.perl.misc)
  • Re: global substitution with files
    ... rid of spaces, and apostrophes and such. ... then re-open it and overwrite it with the array. ... Why need to slurp the file into a scalar?It consume your memory ...
    (perl.beginners)