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

Hi Ken Thanks for your reply and the info on the mod tie One more question. Does that replace all of the instances or just the first one it gets to ? Thanks again

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

    It operates on every line. On each line, there will be, at most, one substitution. If you want multiple substitutions on a line, add the 'g' modifier (see perlre for details) like this:

    s/the line to be replaced/this is the new line/g

    -- Ken

      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.

        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

      Hi Ken, Your example of tie was awesome . I figured out how to fix my code with your example. I did not use tie But you really helped me and I sure do appreciate it
      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.
      Thanks ken for the code . I really appreciate it.