Steve Hemond wrote:
>
> I need to insert the ESC character followed by a couple of other
> characters at the beginning of a text file without overwriting it. What
> is the best way to do it?

Hi Steve.

When you say 'without overwriting it' do you mean that you want to keep a
backup copy or that you don't want to rewrite the entire file? If it's the
latter then you're out of luck, but don't decide that it's going to be too
slow without trying it.

Tie::File may be your best bet here. It lets you edit text lines from your file
by just changing the array elements. The change is made straight away and the
module is intelligent about buffering and doesn't read or write any more than
it needs to.

You can best express the escape sequence you want to add with "\e" followed by
the exact sequence. For instance, "\e[2J" is ANSI clear-screen.

Take a look at this program. I hope it helps.

Rob



  use strict;
  use warnings;

  use Tie::File;

  tie my @file, 'Tie::File', 'file.txt';

  $file[0] = "\e[2J".$file[0];

  untie @file;



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to