On Mon, Mar 07, 2005 at 11:00:49AM -0500, Wiggins d'Anconia wrote: > Charles K. Clarkson wrote: > >Suneel Kumar B <mailto:[EMAIL PROTECTED]> wrote: > > > >: I have a situation where in, iam updating a file by replacing few > >: strings in some lines with another string. While doing this, Can i > >: have an option by which i could open a file for both read and > >: write simultaneously, so that i could search and replace the > >: string straight away..?? > > > > Sounds like you need in place editing. Check out the -i switch > >in the 'perlrun' documentation for an example. > > > >Charles K. Clarkson > > or Tie::File, > > perldoc Tie::File > > http://danconia.org
The literal answer to your question would be this: open FILE, '/path/to/the/file', '+<' or die "Couldn't open: $!"; or, preferably (as it will manage some safety issues for you): use IO::File; my $file = new IO::File('/path/to/the/file', '+<') or die "Couldn't open: $!"; This isn't a great solution for updating text files, however, since they have variable-length records (e.g., you overwrite a 10-character sentence with 12 characters and you have just stomped on the next 2 characters). One of the above solutions (-i or Tie::File) will stand you in better stead. --Dks -- [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>