costas has asked for the wisdom of the Perl Monks concerning the following question:
This works fine and is no problem but I hate the fact that I have to write to a new file and not write to the file i am reading from. I have tried to write code which allows me to open and write to the file itself, but amazingly i have been unsuccseful :-( the code I tried was along the lines of this...my $line; open (FILEHANDLE, "<$new"); open (OUT, ">$new.bak") ; while ($line = <FILEHANDLE>) { $line =~ s/66/$goodrow->{'ClientID'}/g; $line =~ s/0906\s406\s2427/$SIMCard/g; print "$line<br>"; print (OUT $line); print (FILEHANDLE $line); } close FILEHANDLE; close OUT;
Of course it is obvious that this will not work but i cant seem to find the simple way of altering the text within this file once the regex is true. Can anyone give any tips as i havent found the answer elsewhere on the net.my $line; open (FILEHANDLE, ">>$new"); while ($line = <FILEHANDLE>) { $line =~ s/66/$goodrow->{'ClientID'}/g; $line =~ s/0906\s406\s2427/$SIMCard/g; } close FILEHANDLE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: forgetting the simple stuff?
by zejames (Hermit) on Jun 26, 2002 at 09:02 UTC | |
|
Re: forgetting the simple stuff? (-i and $!)
by grinder (Bishop) on Jun 26, 2002 at 09:03 UTC | |
|
Re: forgetting the simple stuff?
by csotzing (Sexton) on Jun 26, 2002 at 10:53 UTC | |
|
Re: forgetting the simple stuff?
by blakem (Monsignor) on Jun 30, 2002 at 10:21 UTC |