in reply to print curly brackets

All great responses. Thanks. As Dave suggests, I need to be more specific about what I'm really asking for. Here goes: I am parsing an .xml file, formatting, and outputting to an .rtf file. Some of the input strings contain curly brackets (a debug print to the screen verifies that these brackets are in the input string) but they simply don't show up in my output rtf file. So I've tried several substitutions. All 4 of these options cause Word to believe that the output rtf file is corrupted and won't allow me to even open it:

$formatline =~ s/\{/\{/g;

or

my $left_bracket = chr(123); $formatline =~ s/\{/$left_bracket/g;

or

my $left_bracket = "{"; $formatline =~ s/\{/$left_bracket/g;

or

my $left_bracket = '{'; $formatline =~ s/\{/$left_bracket/g;

The only success I've had is changing the { to a ( as follows:

$formatline =~ s/\{/(/g;

Replies are listed 'Best First'.
Re^2: print curly brackets
by Anonymous Monk on Jul 12, 2011 at 16:01 UTC

    but they simply don't show up in my output rtf file.

    Great start, but your code doesn't demonstrate that -- it doesn't generate a rtf file which doesn't show {}

    All your examples s/\{/{/g; will replace braces all day and all night :) but they won't necessarily make them appear visible in a rtf document :)

    It is basic escaping problem -- { and } are special in RTF, so use one of RTF::Parser / RTF::Lexer / RTF::Writer

Re^2: print curly brackets
by ikegami (Patriarch) on Jul 12, 2011 at 16:59 UTC

    $formatline =~ s/\{/\{/g; doesn't do anything. It replaces «{» with «{». Perhaps you want to replace «{» with «\{»?

    $formatline =~ s/\{/\\{/g;

    I'm just guessing. I don't know RTF, and you didn't specify what you wanted to do.