in reply to access to sub of package

The "usage" function is in the "A" namespace, therefore... A::usage(...)

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Replies are listed 'Best First'.
Re^2: access to sub of package
by jeanluca (Deacon) on Feb 28, 2006 at 14:55 UTC
    Well, that didn't work. Here is some code that demonstrates how I did it:
    package B:
    package B ; sub usage { print "test\n" ; }

    main script
    use B ; B::usage() ;
    If I run this script I get:
    Undefined subroutine &B::usage called at ./r.pl line 5. Any suggestions ?

    Luca

      The B module is part of the standard distribution and doesn't have a usage sub, so yeah you'll get an error. Use a better example module name (e.g. Foo or the like) and you'll get better results.

        just one other thing. The difference with the example, and the situation I've here is that I've the package name inside a variable, like: $var = "B" ;Now this doesn't work:
        $var::usage() ;
        But this does
        $var->usage
        Do you know why this is ?

        Thanks
        Luca
        Yep, thnks, I noticed that when I add use lib '.'; it works too!!

        Luca