=pod Embellish as you will (slurpall(), etc. This example only does one file at a time.) When I do this fast or in-line, many times I have accidentally left out the concatenation dot in ( .= ). Depending on your buffer size and file size, it can be a transient error that is a PITA. "Remember the dot". Better, package it. Reading a file a buffer at a time, rather than a line at a time, though, makes slurpping an invaluable tool of the trade (... $/="";). Usage: $html = slurp("index.html"); =cut sub slurp { my $tls = $/; $/=""; open X, $_ or return "No $_\n"; my $slurp .= $_ while (<X>); close X; $/ = $tls; return $slurp; }
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: slurp
by chromatic (Archbishop) on Apr 19, 2000 at 00:32 UTC | |
by Adam (Vicar) on Jun 20, 2000 at 00:31 UTC | |
RE: slurp
by btrott (Parson) on Apr 19, 2000 at 00:15 UTC | |
by Vane (Novice) on Jun 19, 2000 at 10:31 UTC |