Hi,
With regards to the script below, inside the foreach loop, can someone explain 
to me why the expression  $_=~ s/\nfred\n/nancy/;
 did not change the default variable $_ from fred (enclosed by \n) to nancy.

Thanks

######### start of script ###################
use strict; 
open (MYDATA, ">BACCARATDATA.TXT") || DIE  $!;
print MYDATA "hello how are you\nfred\n";
close MYDATA;

open (MYDATA, "<BACCARATDATA.TXT") || DIE  $!;
my @newdata = <MYDATA>;
close MYDATA;

open (MYDATA, ">>BACCARATDATA.TXT") || DIE  $!;
foreach (@newdata){
    $_=~ s/\nfred\n/nancy/;
    print MYDATA "$_";
    print "$_";
}
close MYDATA;

Reply via email to