perl-unicode

utf8::encode causes can't find SWASHNEW error

2006-09-07 12:20:46
Hi!

I'm having trouble getting my head around this issue and
I'm hoping someone can spare a few moments to explain what's
going on.

On a Perl 5.6.1 server, the following reduction:

-------------------

use strict;

my $test = pack "U0A*", "Dan";
print uc($test), "\n";

sub do_nothing {
  utf8::encode('foobar');
}

--------------------

produces a "Can't locate object method "SWASHNEW" via package
"utf8" (perhaps you forgot to load "utf8"?) at line 4." error.
The error is triggered at the uc call.

What I'm not understanding is how just the existence of the
utf8::encode() call triggers the error, even though it is not
actually called by the code. I.E., if you remove the "do_nothing"
sub, the uppercase string is printed and no error is generated.
How would I best write the above reduction for backward
compatibility with Perl 5.6.1? In my real world script that
provoked the above reduction, the actual utf8::encode() call
is in a use'd module.

Any light that could be shed on this, either by link referrals
or direct explanation, would be greatly appreciated!!

Thanks,

Dan

<Prev in Thread] Current Thread [Next in Thread>