in reply to Re: How to ignore ampersand and pound signs?
in thread How to ignore ampersand and pound signs?

Thank you!

The double q (qq) worked!

Sorry for the basic question, I'm just starting out with Perl. :-)

  • Comment on Re^2: How to ignore ampersand and pound signs?

Replies are listed 'Best First'.
Re^3: How to ignore ampersand and pound signs?
by ikegami (Patriarch) on Nov 04, 2009 at 02:33 UTC
    Nonsense. The single quote you originally posted works just as well.
    my $s = q[<IL.Check/>]; my $r = q[<&#x221a;>]; print "Old word: $s\n"; $s =~ s/$s/$r/; print "New word: $s\n";

    There's no interpolation or escape sequences here. q vs qq is moot.

    The real problem is that you are using text as a regex pattern without first converting it to a regex pattern. ("#" is special under "x".) Use quotemeta or its alias \Q..\E:

    my $s = q[<IL.Check/>]; my $r = q[<&#x221a;>]; print "Old word: $s\n"; $s =~ s/\Q$s\E/$r/; print "New word: $s\n";
Re^3: How to ignore ampersand and pound signs?
by Anonymous Monk on Nov 04, 2009 at 01:55 UTC