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

I need to know if there is any way to use a variable (string) when explicitly printing a character. For example:
$bob = "310B"; print "\x{$bob}";
However, this does not work, because $bob is not interpolated. Is there another way to do this? It doesn't have to be using hexidecimal characters, but the value does have to come from a variable.

Replies are listed 'Best First'.
Re: UTF-8 and characters
by Abigail-II (Bishop) on Aug 15, 2002 at 09:01 UTC
    You could of course store the character in variable:
    $bob = chr hex "310B"; print $bob;
    Or use one of the alternatives suggested above.

    Abigail

Re: UTF-8 and characters
by theorbtwo (Prior) on Aug 15, 2002 at 06:00 UTC
Re: UTF-8 and characters
by DamnDirtyApe (Curate) on Aug 15, 2002 at 07:02 UTC

    theorbtwo's solution is the right one. However, since TIMTOWTDI, you could also say:

    my $bob = "310B"; eval qq[print "\\x{$bob}"] ;

    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche