Anish Kumar K. <[EMAIL PROTECTED]> asked: > I wanted to append some line in between a text file. So what > I tried is with the seek command I tried moving the pointer > and then do appeding, but for some reason it was not getting > appended.
When you seek() and write in the middle of a file, it'll overwrite what's already there. > Say I have a text file > > Java > Oracle > Visual basic > > I wanted to insert PERL after Oracle...So now the file should be > > Java > Oracle > PERL > Visual basic > > I did with array. ie first copying the file into array and then doing. > > is there any alternate way First, there is an alternate spelling - the language is Perl, and perl(.exe) is its interpreter. The way it's done is thus: use File::Copy; rename( $filename, "$filename.tmp" ) or die "rename failed: $!"; open( IN, "$filename.tmp" ) or die "open failed: $!"; open( OUT, ">$filename" ) or die "open failed: $!"; while( <IN> ){ print OUT; if( m/^Oracle/ ){ print OUT "Perl\n"; copy( *IN, *OUT ); # or just: print OUT while <IN>; } } HTH, Thomas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>