Rob Nagler <[EMAIL PROTECTED]> writes: > > undef $/; # enable "slurp" mode > > I think the "local" is pretty important, especially in mod_perl: > > local $/; > > This has the same effect (the "undef" is unnecessary). It's also a > good idea to enclose the code in a subroutine with error checking: > > sub read_file { > my($file) = @_; > open(FH, "< $file") || die("error opening $file: $!"); > local($/); > my($content) = <FH>; > close(FH) && defined($content) || die("error reading $file: $!"); > return \$content; > }
A similiar idiom that I saw recently: sub file_contents { my $fn = shift; open(FOO, $fn) or die "file_contents: open($fn): $!\n"; my $stuff; read FOO, $stuff, -s FOO; close(FOO); return $stuff; } Take your pick as to which one is clearer... -Dom -- | Semantico: creators of major online resources | | URL: http://www.semantico.com/ | | Tel: +44 (1273) 722222 | | Address: 33 Bond St., Brighton, Sussex, BN1 1RD, UK. |