John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

It seems that the module alone didn't reproduce the problem I reported with "Attempt to free unreferenced scalar". I got it down to the following test code to reproduce:

If the main file doesn't have use charnames, the problem goes away!

Main program: what.perl

use utf8; use charnames ':full'; use Foo; print "Hello world\n";

Module Foo.pm

use utf8; use charnames ':full'; package Foo; my $LN= "\N{POUND SIGN}"; 1; # loaded OK
Any clues? I take it this must be a Perl bug, since I don't see what I could be doing wrong in something so simple.

—John


Running ActiveState build 809, v5.8.3

Replies are listed 'Best First'.
Re: Internal error from Perl
by graff (Chancellor) on Feb 24, 2004 at 06:00 UTC
    The problem also goes away if you don't use Foo:
    use utf8; use charnames ':full'; # don't use Foo; print "Hello world \N{EURO SIGN} \n"; # no error message
    Meanwhile, when using Foo, and using charnames in both main and Foo, you do get the message, but it is just a warning, and the "\N{...}" construct really does work in both name spaces:
    use utf8; use charnames ':full'; use Foo; print "Hello world \N{EURO SIGN} $Foo::LN \n"; # "unreferenced scalar" message shows up, but so do both # intended characters (assuming you have the right font...)
    Anyway, I'd agree that this merits a bug report.
Re: Internal error from Perl
by halley (Prior) on Feb 24, 2004 at 21:03 UTC
    I'm not at a machine with a recent perl, so I haven't even tried to reproduce this. I'm just theorizing and kibbitzing from the side.

    If you load module with the 'use' statement, some symbols may be imported into your current package's namespace. The 'package' statement changes your current package AT THAT POSITION. Your current code, if viewed as a single stream, reads like this:

    package main; use utf8; use charnames ':full'; use utf8; use charnames ':full'; package Foo; { ... code using utf8 ... } package main; { ... code not using utf8 ... }
    In modules, you should START with your package name, then bring in any other modules you want to use in defining that package's implementation.
    package Foo; use utf8; ... 1;

    --
    [ e d @ h a l l e y . c c ]

Re: Internal error from Perl
by ambrus (Abbot) on Feb 24, 2004 at 21:28 UTC
    I take it this must be a Perl bug, since I don't see what I could be doing wrong in something so simple.

    Never say that. I learned this from practice.