[thelist] Configuring Perl on NT/IIS4.0
Dwayne Holmberg
dholmberg at media-logic.net
Wed, 5 Jan 2000 14:04:44 -0700 (MST)
Ron White writes:
> Got a suggestion from the MJ list to use ActiveStatePerl,
> www.activestate.com, worked like a charm. 6 meg DL and just click through
> and it takes care O' bidniz....
you were building and installing on windows yourself? you're a braver man than I. Gotta agree, activestate's done some fine work.
- dwayne
<tip type="perl">
I don't write two scripts without using this subroutine, so thought someone else might find it usefull. It takes one or more filenames as a parameter, slurps up the contents and returns a referernce (or list of references) to them. The funky bit is using local on $/ (the record seperation variable) to temporarily undef it, meaning no record seperation, which means when you do:
$slurps[$i] = <FH>;
you get the whole file pointed to by the file handle, rather than just one line.
#------------------------------------------------------------------------
# Function: grabFiles
# Description: sucks whole files into an array
# Parameters: file(s) to slurp
# Returns: reference to scalar or array with files, undef on fail
#------------------------------------------------------------------------
sub grabFiles {
my (@files) = @_;
my ($i, @slurps);
# delimiters? we don't need no stinkin' delimiters.
local $/ = undef;
$i=0;
for my $file(@files) {
open (FH, $file) or return undef;
$slurps[$i] = <FH>;
close (FH);
$i++;
}
wantarray ? return \@slurps : return \$slurps[0];
}
# end grabFiles
</tip>