If you think it is just a question of what I am "used to", then you need to read more carefully. If you don't understand how "vars" works, then you should correct that, because it is really simple and occasionally useful.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.