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

When you use a module in a script, any variables defined in that module with our (instead of my) are automatically exported.

Can you post some code that demonstrates this?

Replies are listed 'Best First'.
Re: Re: Re: Sharing the scalar love?
by exussum0 (Vicar) on Dec 22, 2003 at 21:21 UTC
    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..

      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..
          A reply falls below the community's threshold of quality. You may see it by logging in.
      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)