Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
No such thing as a small change
 
PerlMonks  

Re: global variables defined in an external file

by Anonymous Monk
on May 06, 2013 at 15:48 UTC ( #1032332=note: print w/ replies, xml ) Need Help??


in reply to global variables defined in an external file

Really, the question to ask is how many are the global variables? I know it's good practice not Export variables, but if it must be done, you can do: The pm file:

package Def; use warnings; use strict; use vars qw(@ISA @EXPORT $foo $bar $boo); BEGIN{ require Exporter; Exporter->import(); } @ISA = qw(Exporter); @EXPORT = qw($foo $bar $boo); 1;
The file which uses the pm file
#!/usr/bin/perl use warnings; use strict; use Def; # the variable defined module $foo = 'you can\'t foo me'; $bar = 'Let\'t meet in the bar'; $boo = 'The fans boo you today'; print $boo,$foo,$bar;


Comment on Re: global variables defined in an external file
Select or Download Code
Re^2: global variables defined in an external file
by fionbarr (Monk) on May 06, 2013 at 15:52 UTC
    thanks for your very clear response....however, I'd like to do this
    $foo = 'you can\'t foo me'; $bar = 'Let\'t meet in the bar'; $boo = 'The fans boo you today';
    in the module and reference these variables in the calling program as: print $boo, etc.
Re^2: global variables defined in an external file
by choroba (Abbot) on May 06, 2013 at 15:58 UTC
    It is the ohter way round:

    Def.pm:

    package Def; use warnings; use strict; use Exporter 'import'; our @EXPORT = qw/$sc @ar %ha/; our $sc = 'All'; our @ar = qw/the variables/; our %ha = (exported => ' succesfully.'); __PACKAGE__
    The script:
    #!/usr/bin/perl use warnings; use strict; use Def; print "$sc @ar ", %ha;
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1032332]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-04-21 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (489 votes), past polls