File::Slurp allows you read a filehandle into a scalar.
However there is another way to do this without having to load an extra module at runtime.
The select statement changes $/ (the input record separator) to a null character instead of a \n. And there you go..
#!/usr/bin/perl my $file="foobar"; open (FILE, $file) or die "Can't open $file: $!\n"; select((select(FILE), $/ = undef)[0]); my $contents = <FILE>; close (FILE);
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: Load file into a scalar without File::Slurp
by merlyn (Sage) on Jun 28, 2000 at 23:32 UTC | |
by BlueLines (Hermit) on Jun 29, 2000 at 01:15 UTC | |
by matthew (Acolyte) on Jul 14, 2000 at 20:58 UTC | |
by merlyn (Sage) on Jul 16, 2000 at 18:32 UTC | |
RE: Load file into a scalar without File::Slurp
by audreyt (Hermit) on Jul 25, 2000 at 01:25 UTC | |
RE: Load file into a scalar without File::Slurp
by turnstep (Parson) on Jul 17, 2000 at 04:23 UTC | |
by chromatic (Archbishop) on Jul 17, 2000 at 08:09 UTC |
Back to
Cool Uses for Perl