http://qs1969.pair.com?node_id=2878


in reply to Return the contents of a file

Two things:

1) that while loop should read:

while (<FS>) { $OP .= $_ }
Note the all-important ".=" instead of "=" (probably just a mistype on your part. :)

2) your opens should always check for error messages, and you should get faster results slurping the whole file in as one string, like so:

sub readfile { my $OP; open FS, $_[0] or die "Can't open $_[0]: $!"; { local $/ = undef; $OP = <FS>; } close FS or die "Can't close $_[0]: $!"; return $OP; }