singam has asked for the wisdom of the Perl Monks concerning the following question:

dear monks, i saw the posts in "help needed in unicode displaying" and i tried to do some program.i came across the following problem.In the $target variable, I stored some chinese characters (for example three chinese characters), I tried to get first two chinese characters using substr $target,0 2 ; , but its not giving the appropriate answer. any one give me the solution to retrieve the first two chinese characters,

Replies are listed 'Best First'.
Re: help needed in unicode retriving
by wazoox (Prior) on Mar 10, 2006 at 12:25 UTC
    Perhaps should you tell perl you want to use unicode first with :
    use open ':utf8';
    Hope that helps.

    update: Well actually it should even be

    use utf8;

    Then all strings will be treated as utf8. "use open ':utf8'" is for opening and writing to utf8 files.

      but still its giving the wrong answer, substr $target,0,2 it returns only one chinese character , but how to get two chinese characters
        Sorry, my mistake, actually use utf8; should do the trick, see the update to my previous message.