Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

escape single quotes in a hash

Status
Not open for further replies.

CherylD

Programmer
May 1, 2001
107
CA
I have a hash of values that replace holders within an rtf document. when one of the hash values ($dict{COMMENTS}) contains a single quote the whole value is not placed on the document.

This is what is being done:
foreach $key(%dict) {
$dict{$key}=~ s/\*/\\\*/g;
$dict{$key}=~ s/\'/\\\'/g; #THIS DOENS'T SEEM TO BE DOING ANYTHIGN
$text =~ s/\%$key\%/$dict{$key}/g;
}

Any suggestions?
 
Don't know if it'll make any difference, but you could try this:
Code:
foreach $key(%dict) {
  $text =~ s/\%\A$key\Z\%/$dict{$key}/g;
}

----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Actually, looking at it again, I'm pretty sure that's not going to do anything helpful. You say $key is 'COMMENTS' when it fails, so escaping it in the regex is pointless.

Can you say what's in $dict{COMMENTS} and maybe the section of $text you expect to change and how it doesn't?

Also, how are you editing the RTF document? Using a module, like RTF::Document or something I hope?

----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top