in reply to Return the contents of a file
Two things:
1) that while loop should read:
Note the all-important ".=" instead of "=" (probably just a mistype on your part. :)while (<FS>) { $OP .= $_ }
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; }
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: Return the contents of a file
by turnstep (Parson) on Apr 12, 2000 at 18:02 UTC | |
by anders (Initiate) on May 26, 2000 at 17:41 UTC | |
RE: RE: Return the contents of a file
by Chris (Novice) on Apr 12, 2000 at 05:50 UTC | |
by btrott (Parson) on Apr 12, 2000 at 07:18 UTC |
In Section
Cool Uses for Perl