in reply to Re: seek and replace for exceptional characters
in thread seek and replace for exceptional characters

Hi, I just tried quotemeta with my new $A code which is '#i1*#lper/2+#ginsl-#cdz/2'. But it does not work with and without quotementa. I know its a mix of everything but somehow I would like to replace it without interpretation. So my code would be now:
#!/usr/bin/perl -w #use strict; my $SCU = 'C:/Users/user/Desktop/a.txt'; open (FILE, '<', $SCU) or die "$SCU File not found : $!"; my @lines = <FILE>; close (FILE); my $A= quotemeta '#i1*#lper/2+#ginsl-#cdz/2'; my $B= '$coin22'; my @newlines; push @newlines, s/$A/$B/rg for @lines; open (FILE, '>', $SCU) or die "Could not open file $SCU: $!"; print FILE @newlines; close (FILE);
Somebody has a suggestion for me? Thanks a lot! Best regards

Replies are listed 'Best First'.
Re^3: seek and replace for exceptional characters
by marinersk (Priest) on Sep 23, 2013 at 22:09 UTC
    Suggestion #1: Uncomment the use strict; line. Set it to autodestruct your computer if you ever accidentally comment it out again.

    Suggestion #2: Withdrawn. I just upgraded to v5.16.3 and your script runs just fine.

    Suggestion #3: Supply test data as previously noted. :-)

Re^3: seek and replace for exceptional characters
by toolic (Bishop) on Sep 23, 2013 at 18:33 UTC
    Somebody has a suggestion for me?
    Yes. Show a line of your input file which should match this regular expression.