J
Jeff Thies
I have a file that I need to make some substitutions in:
open FH, "my_file" or die "Can't open... $!";
@file=<FH>;
Can I read the file handle so it is a scalar and I can just do this?:
$file=~s/replace_me/with_this/gis; # small files
and then print back to a filehandle.
Or should I do something like this:
my @new_file=();
while(<FH>){
$_=~s/replace_me/with_this/gi;
push @new_file, $_;
}
and then print @new_file to a filehandle? Or would that be a reference
to @new_file?
Seems like there should be a better way than any of these.
Jeff
open FH, "my_file" or die "Can't open... $!";
@file=<FH>;
Can I read the file handle so it is a scalar and I can just do this?:
$file=~s/replace_me/with_this/gis; # small files
and then print back to a filehandle.
Or should I do something like this:
my @new_file=();
while(<FH>){
$_=~s/replace_me/with_this/gi;
push @new_file, $_;
}
and then print @new_file to a filehandle? Or would that be a reference
to @new_file?
Seems like there should be a better way than any of these.
Jeff