Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Assume that the file has the following content,open '+<', '<file.txt';
I want to make it to this way1 2 3 4 5
I followed this way,1 two hi hello 3 4 5
but which removes all the following lines and makes the file like this,open FH, '+<file.txt'; while (<FH>) { print $_; if ( /^2/ ) { print FH "two\nhi hello\n"; } }
What is the issue ? So i would like to know what is the best method to read and write in to the same file.1 2 two hi hello
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: what is the best method to read and write in a file in perl
by moritz (Cardinal) on Sep 17, 2010 at 14:04 UTC | |
|
Re: what is the best method to read and write in a file in perl
by BrowserUk (Patriarch) on Sep 17, 2010 at 15:34 UTC | |
|
Re: what is the best method to read and write in a file in perl
by dasgar (Priest) on Sep 17, 2010 at 14:39 UTC | |
by superfrink (Curate) on Sep 17, 2010 at 16:52 UTC | |
|
Re: what is the best method to read and write in a file in perl
by pemungkah (Priest) on Sep 17, 2010 at 18:25 UTC | |
|
Re: what is the best method to read and write in a file in perl
by jakeease (Friar) on Sep 18, 2010 at 01:30 UTC |