in reply to Substr cannot extract last special character

Hi, It shows Ù, when used -2 offset, due of two byte length of unicode chars.
#!/usr/bin/perl my $ohm = qw(24Ù); $unit = substr $ohm,-2; print "$unit","\n";

Replies are listed 'Best First'.
Re^2: Substr cannot extract last special character
by dave_the_m (Monsignor) on Aug 19, 2005 at 10:45 UTC
    In particular, if you embed utf8 chars in the program source, you have to let perl know with the utf8 pragma:
    my $x ='Ù'; print length($x), "\n"; # prints 2
    compared with
    use utf8; my $x ='Ù'; print length($x), "\n"; #' prints 1

    Dave.