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

I can't seem to reference a package indirectly if the package name starts with a numeric.

The script:
use strict; no strict 'refs'; my $pkg = '006CONFC'; eval "require $pkg" or warn $@; my $ref = *{${ $pkg . '::'}{'post'}}{CODE}; $ref or exit(0); $ref->();
The pm:
package 006CONFC; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(post); sub post { print "MADE IT\n"; } 1;

Using the debugger or -w, I get "Use of uninitialized value in ref-to-glob cast" on the my $ref line. I then change '006CONFC' in the script to something like 'x006CONFC' and create x006CONFC.pm. The script works fine. Does anyone know the reason or even better, the solution?

Replies are listed 'Best First'.
Re: Package starting with numeric not recognized
by ikegami (Patriarch) on Sep 09, 2009 at 20:17 UTC
    Each component of a namespace must be a valid identifier. You can't have a var named @006CONFC, so you can't have one named @006CONFC::ISA either!

      I have not worked extensively with namespaces and so it did not occur to me that they are akin to variables. Now it makes sense. Thanks for the explanation.

Re: Package starting with numeric not recognized
by almut (Canon) on Sep 09, 2009 at 19:57 UTC
    $ perl -e'package 006CONFC' syntax error at -e line 1, near "package 006" Execution of -e aborted due to compilation errors.

    My guess would be that package names (namespaces) simply can't start with a digit — just like variable names etc.  (except for the builtin ones like $1 of course)