in reply to Substitution for braces

See perlre, or perlretut, or quotemeta or perlop on \Q...\E.

Replies are listed 'Best First'.
Re^2: Substitution for braces
by gem555 (Acolyte) on Jul 09, 2009 at 04:39 UTC
    Can I use the code similar to this?
    #!/usr/bin/perl while ($line = <DATA>){ $line =~ s/<cc>([\s\S]+?)<\/cc>/defined ($1) ? "(&amp;amp;|&amp;)" : ' +-'/eg; print $line; }
    This prints out (&amp;|&). But replacing of &amp; and & doesnot gets replaced with '-'.

      Is this a different question to your original question? I don't understand it. The data in your original question does not have <cc> in it.

        In xml file, & I have to substitute in <cc>Some text </cc> So when i read the file, the <cc> tag is with other tags also. Even there also & is replaced with '-'. In the example below:
        if($line =~ /<cc>([\s\S]+?)<\/cc>/){ #$line = $1; $line =~ s/&amp;amp;/-/g; $line =~ s/&amp;/-/g; $line =~ s/-$//g; }
        if I assign $line to $1, then in the output rest of the strings are removed and only $1 is visible.