in reply to Re: Re: Sharing the scalar love?
in thread Sharing the scalar love?

S.pm...

package S; use strict; use warnings; our $x = 1;

And here is a script using S.pm

use strict; use warnings; use S; print $S::x; print "\n";

Play that funky music white boy..

Replies are listed 'Best First'.
Re: Re: Re: Re: Sharing the scalar love?
by chromatic (Archbishop) on Dec 22, 2003 at 21:24 UTC

    Where's the export? Do you mean something besides "creates an entry in the caller's symbol table"?

      I misunderstood then. Do you mean like...

      S.pm....

      package S; use strict; use warnings; require Exporter; @S::ISA = qw(Exporter); @S::EXPORT = qw($x); our $x = 1; 1;

      And t.pl again..

      use strict; use warnings; use S; print $x; print "\n";
      I hate this since it imports into the user's symbol table.. which I hate. I prefer my first answer since it's less prone to mucking up the user space.

      Note: someone reply to my bad usage of @S::ISA. Someone prolly knows of a better way of doing this with strict on :)


      Play that funky music white boy..
        Note: someone reply to my bad usage of @S::ISA. Someone prolly knows of a better way of doing this with strict on :)
        Howabout (for perl 5.6.0 and up):
        package S; our @ISA = qw(Exporter);
        Or use vars qw(@ISA) for older perls.

        At least it doesn't make you type the package name, which is error prone, since it creates a new package if you spell it wrong.

        Joost.

        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Re: Re: Re: Sharing the scalar love?
by jcpunk (Friar) on Dec 22, 2003 at 21:28 UTC
    eureka!
    (insert Archimedes running naked through the streets with joy.... or how about not, your call)

    Thank you greatly.


    jcpunk
    all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)