in reply to Re: Replacing the pattern to search for
in thread Replacing the pattern to search for

Actually the thing is that I want to retain the size of the code by inserting the space whereever that particular $pattern exists. The second while is used as there can be any no. of lines before there the pattern is found.
  • Comment on Re^2: Replacing the pattern to search for

Replies are listed 'Best First'.
Re^3: Replacing the pattern to search for
by sasikumar (Monk) on Jan 18, 2005 at 12:05 UTC

    So here is the code
    use strict; my $file_name="c:\\temp.txt"; open (FH,"$file_name"); my $pattern="some thing"; my $c=0; my $space=' '; my $line; while(<FH>) { $line=$_; #current line $c++; #counts the number of lines $space=' ' x $c .' ' x length($pattern); #pattern that has to be r +eplaced $line=~s/$pattern/$space/i; }

    Thanks
    SasiKumar