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).
foo.pl
#!/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";
Bar.pm
#!/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;
result
[sandy][~] perl foo.pl
one two three four
1 2 3 4
I'm not sure I see the difference between our and use vars
UPDATE
Thank you ikegami. Now I get it.
|