Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^13: the "our" declaration ?!! (special vars)

by Sandy (Curate)
on Jan 21, 2009 at 20:56 UTC ( #737950=note: print w/ replies, xml ) Need Help??

in reply to Re^12: the "our" declaration ?!! (special vars)
in thread the "our" declaration ?!!

Sorry if I misunderstand what you say

What vars does is declare a certain global in a certain package so that strict will not complain about it. If you have a package that crosses files, the declaration will cover both (assuming it happens in the first one Perl compiles).
#!/usr/bin/perl use strict; use warnings; package Foo; use Bar; our $one; our $two; use vars qw($three $four); $one = 'one'; $two = 'two'; $three = 'three'; $four = 'four'; print "$one $two $three $four\n"; Foo::switch(); print "$one $two $three $four\n";
#!/usr/bin/perl use strict; use warnings; package Foo; our $one; our $two; use vars qw($three $four); sub switch { $one = 1; $two = 2; $three = 3; $four = 4; } 1;
[sandy][~] perl one two three four 1 2 3 4
I'm not sure I see the difference between our and use vars


Thank you ikegami. Now I get it.

Comment on Re^13: the "our" declaration ?!! (special vars)
Select or Download Code
Replies are listed 'Best First'.
Re^14: the "our" declaration ?!! (special vars)
by ikegami (Pope) on Jan 21, 2009 at 21:22 UTC

    Try commenting out

    use vars qw($three $four);

    in Then try commenting out

    our $one; our $two;


      Yeah but this saves just one line in, a benefit restricted to cases where I don't wanna use the import() method!

      Sandy thanks for the code-example, makes it much clearer! : )

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2015-12-01 19:40 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (26 votes), past polls