Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Unusual variable declaration

by davido (Cardinal)
on Nov 04, 2019 at 19:28 UTC ( #11108308=note: print w/replies, xml ) Need Help??


in reply to Re^2: Unusual variable declaration
in thread Unusual variable declaration

You are not wrong in the details of what our accomplishes. But it is referred to as a declaration in the documentation for our:

An our declaration declares an alias for a package variable that will be visible across its entire lexical scope, even across package boundaries. The package in which the variable is entered is determined at the point of the declaration, not at the point of use.

Fortunately it does what it does regardless of what we call the behavior. :) It might be a case where there's not a one or few word name for the action our takes. But I do acknowledge your point; our is not a declaration in the say way that my is, or even int foo; in C. It would be nice if we had a word for it that isn't "relax the requirement for fully qualifying the name within a lexical scope under strict."


Dave

Replies are listed 'Best First'.
Re^4: Unusual variable declaration
by LanX (Archbishop) on Nov 04, 2019 at 22:25 UTC
    > our is not a declaration in the say way that my is

    Why?

    My is creating a pad entry for a lexically scoped variable, allocating and initializing it.

    A pad is a symbol table in a hash structure similar to a stash.

    Our is basically doing the same thing, apart from skipping to allocate space if the variable already exists.

    My's destruction at the end of scope is hardly a criterion for declaration.

    The pad is private, the stash is public and global. That's the basic difference.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      The point is that our is not doing the same thing. Not even basically. It might look like it does if you use it once, but as soon as you have several ours for the same variable in separate blocks it's clear our is not doing anything like my.

      Jenda
      1984 was supposed to be a warning,
      not a manual!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2020-05-24 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (142 votes). Check out past polls.

    Notices?