Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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.

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2018-02-25 21:55 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (315 votes). Check out past polls.