On Thu, 07 Sep 2006 15:20:34 -0400, Dan Ragle
<daniel(_at_)Biblestuph(_dot_)com> said:
> 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?
By adding 'use utf8' or 'no utf8'.
> 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!!
I cannot explain, so I'm tempted to call it a bug.
Apparently some code looks up the symbol table and if utf8:: is there,
then it does something that usually is only available when utf8 is
loaded. So by actually making sure utf8 is loaded, you give that code
what it needs.
--
andreas