in reply to Re^3: A Better Way
in thread A Better Way

Thanks Ken for your below link to tie and your answers. The reason I created my program in the above way Is so it only replaces the first line in the loop not every line it loop . It seems crazy but I need this in the program I am creating.

Replies are listed 'Best First'.
Re^5: A Better Way
by kcott (Archbishop) on Nov 04, 2010 at 18:43 UTC

    If it's only for the first line, use this instead:

    use strict; use warnings; use Tie::File; tie my @xfil, 'Tie::File', 'var.txt' or die $!; $xfil[0] =~ s/the line to be replaced/this is the new line/; untie @xfil;

    Substantially less cumber. :-)

    -- Ken