M
MJS
Can someone help me with the following code.
It just saves/prints the line in which 'hello' occured.
why doesn't it save the entire file i.e why don't i get the entire
content of file1 in file2 ?
open(FILEREAD, "file1") or die "Can't open file1: $!\n";
while(<FILEREAD>) {
#searching the string
if(/hello/) {
open(FILEWRITE, ">file2") or die "Can't open file2: $!\n";
select FILEWRITE; # this is not needed.
print FILEWRITE ;
close(FILEWRITE);
}
}
close(FILEREAD);
It just saves/prints the line in which 'hello' occured.
why doesn't it save the entire file i.e why don't i get the entire
content of file1 in file2 ?
open(FILEREAD, "file1") or die "Can't open file1: $!\n";
while(<FILEREAD>) {
#searching the string
if(/hello/) {
open(FILEWRITE, ">file2") or die "Can't open file2: $!\n";
select FILEWRITE; # this is not needed.
print FILEWRITE ;
close(FILEWRITE);
}
}
close(FILEREAD);