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). If you declare a variable then change packages, the declaration stops having an effect. In short, vars actually works like ikegami claimed that our did.
Simple, huh? What is it good for? In the unlikely situation that you want to share a global in 2 very different places, vars is the best way to do it. If in one file you need to declare something in another, vars is the only way to do it. (Luckily exporting a variable with Exporter also declares it, so you very rarely need to do that.) The only real benefit that our has over vars is that you can save one line on certain often-used declarations. (I don't consider obfuscation to be a benefit.) Other than that saving of typing, there is always a better way to do it.
On the missing orthogonality of how you can use local, that is Larry Wall's executive decision. He thought that using local on my variables would be too confusing, and so has deliberately rejected patches that would change that. I definitely don't blame that on our, however it is a difference and I like keeping track of differences.
But I personally don't often want to do local lexical variables. What has proven more useful for me is using local on the keys of a hash instead.
In reply to Re^12: the "our" declaration ?!! (special vars)
by tilly
in thread the "our" declaration ?!!
by perlpal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |