jc23 has asked for the wisdom of the Perl Monks concerning the following question:
I'm having trouble with a simple search and replace. I'm searching and replacing a string in the file. The substitution is correct, however, I can't get it to make changes in the file. Everytime I make changes nothing gets changed in the actual file. Can anyone help? Thanks. I have the following code:
I also tried this which didnt change the actual file either:#! /usr/bin/perl; use File::Copy; #! /usr/bin/perl; use File::Copy; $^I = '~'; open (IN, "file.txt"); s/To: [\.\@\D\,]*/To: someone\@email.com/ while <IN>; close(IN);
thanks~open (INFILE, "<$dirContent"); open (OUTFILE, "<$dirContent"); while (my $row = <INFILE>) { if($row =~ /Cc:/){ $row =~ s/Cc: [\.\@\D\,]*//; print OUTFILE $row; } if( $row =~/^To:/){ $row =~s/^To: [\.\@\D\,]*/To:email\@mail.com/; print OUTFILE $row; } print OUTFILE $row;} } close (INFILE); close (OUTFILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: replacing in file
by skyknight (Hermit) on Aug 01, 2003 at 17:52 UTC | |
by jc23 (Acolyte) on Aug 01, 2003 at 17:57 UTC | |
by sgifford (Prior) on Aug 01, 2003 at 18:13 UTC | |
by skyknight (Hermit) on Aug 01, 2003 at 18:16 UTC | |
|
Re: replacing in file
by Anonymous Monk on Aug 01, 2003 at 18:01 UTC | |
|
Re: replacing in file
by blue_cowdawg (Monsignor) on Aug 01, 2003 at 18:05 UTC |