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

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

Replies are listed 'Best First'.
Re^4: A Better Way
by toniax (Scribe) on Nov 04, 2010 at 18:22 UTC
    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

Re^4: A Better Way
by toniax (Scribe) on Nov 04, 2010 at 22:13 UTC
    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
Re^4: A Better Way
by toniax (Scribe) on Nov 04, 2010 at 18:29 UTC
    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.
Re^4: A Better Way
by toniax (Scribe) on Nov 04, 2010 at 18:53 UTC
    Thanks ken for the code . I really appreciate it.