I'm reading an xml file in utf8 format. I want to strip out the xml and convert the data to iso-8859-2 octal codes for any letter not in the standard 7 digit ascii letters. So far it looks like my code works 99% of the time. But for some characters like a dash '-', it is converting it into a question mark '?'. Does this mean that it could not encode from a unicode - to the standard ascii - ?
Here is some code snippet:
use Encode; sub convertData { my $tempString = encode("iso-8859-2",shift); my $newString = ""; for ( my $l=length( $tempString), my $i = 0; $i < $l; $i++ ) { my $chr = substr( $tempString, $i, 1 ); my $ascii = ord( $chr ); if ( ( $ascii < 32 ) or ( $ascii > 126 ) ) { $newString .= sprintf("\\%03o", $ascii); } else { $newString .= $chr; } } return $newString; }
Also, I am fairly new to perl and encoding, so let me know if I am doing something that is not safe or totally correct.
In reply to convert utf8 to iso-8859-2 to octal code by sdperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |