I just had to do something like this yesterday, and I couldn't figure out how to do it in just one regex, but I did find a way that you could use. I have a database giving me single and double quotes in variables as their octal equivalent. I get a variable from the database as:
Dan\047s \042Baby\042
and I need the variable converted back to:
Dan's "Baby"
So, I did the following, @words is a list of variables to convert
# change octal \0nn to the appropriate character
foreach (@words) {
while ($_ =~ /\\(0\d{2})/) {
my $myChar = chr(oct $1);
$_ =~ s/\\$1/$myChar/g;
}
}
This works, but I am sure there is a better way to code this, and I was thinking of asking that when I had time. To use it, instead of coverting newlines to \n, convert them to \012.
Thanks for the suggestion.
I'm mostly concerned about the interaction of \\ and \n in pathological cases like the string "\\\n\n\\n". Which one do I convert first? <laughs>
Since you're helping me, I'll give you a tip. The above loop is the same as:
s/\\(0\d\d)/chr(oct $1)/ge foreach @words;
Thanks again.
James
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>