in reply to Re^4: substitute on file line by line not working syntax error
in thread Search and Replace line by line not working on Filehandle
Input file was:use warnings; use strict; use Fcntl qw(SEEK_CUR); # open existing file for read/write open (my $in, '+<', 'file1.txt') || die "Unable to open file1.txt:$!"; while (<$in>) { # Identify the record if (/4444/) { # Construct the new record s/4/#/g; # Position the file pointer seek ($in, -length($_)-1, SEEK_CUR); print $in $_; } } close $in;
file after processing is:111111111111111 22222222 33333333333 4444444 5555555555555555 66666666666
111111111111111 22222222 33333333333 ####### 555555555555555 66666666666
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: substitute on file line by line not working syntax error
by matze77 (Friar) on Jan 15, 2010 at 11:03 UTC | |
by cdarke (Prior) on Jan 15, 2010 at 11:28 UTC | |
by matze77 (Friar) on Jan 16, 2010 at 16:02 UTC |