in reply to Re^4: Delete a line from the file
in thread Delete a line from the file

I think you are over-escaping the shell.

Since you are in single-quotes, attempting to escape the $ using \$ causes the $ to be interpreted literally by perl where you did not intend.

Specifically, I think you intended perl to see "$var" , but you have a "\" preceding the $ , and that \ is passed to perl, so perl thinks you want a literal $var, instead of interpolating.

Here is how perl currently sees your re:

s#\Q(.*)\$/',\$lines,\$matches))10.(.*)\$/',\$lines,\$matches))(.*)\ +$/',\$lines,\$matches))# #gi
You need to remove all attempts to escape all $'s in front of variable names.

Update:The problem is that \Q interpolates and disallows \$ - see my response below.

     Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

Replies are listed 'Best First'.
Re^6: Delete a line from the file
by ajd335 (Novice) on Jul 16, 2008 at 23:37 UTC
    Hi , yeah I have tried removing all the '\' before the '$' But still the same..No matched pattern stored in result1.txt Thanks,
      This one works:
      perl -ne 'BEGIN{ $s=q ~(.*)$/'"'"',$lines,$matches) 10.(.*)$/'" +'"',$lines,$matches) (.*)$/'"'"',$lines,$matches)~};print unless +/\Q$s\E/' input.txt
      Instead of doing an in-place replace , You can redirect the output of this to the final file.

      It seems like "\Q" and the "$" symbol do not interact well when directly in a RE.

      If you put the "$" symbols outside \Q..\E , it seems to work.

      Here is the quote from http://www.perl.com/doc/manual/html/pod/perlre.html

      You cannot include a literal $ or @ within a \Q sequence. An unescaped $ or @ interpolates the corresponding variable, while escaping will cause the literal string \$ to be matched. You'll need to write something like m/\Quser\E\@\Qhost/.

      So, this one works too ..(But it sure is UGLY!)

      perl -ne 'print unless m~\Q(.*)\E\$/'"'"',\$lines,\$matches\Q) + 10.(.*)\E\$/'"'"',\$lines,\$matches\Q) (.*)\E\$/'"'"',\$lines,\$ +matches\)~x' input.txt

           Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

        Hi Netwallah, Thanks for the help..Actually , I have added some extra code in my PHP script , and its working fine now. But, I really like the solution that you have given. It helped me a lot , as I was not aware of such things. Thanks to all who helped me in solving out the matter..