Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Unusual variable declaration

by LanX (Saint)
on Nov 04, 2019 at 14:44 UTC ( [id://11108300]=note: print w/replies, xml ) Need Help??


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

Yes and no ... the definitions vary.

What's happening is declaration, allocation and initialization.

You are right that our $var declares a "lexical alias" to $__PACKAGE__:var

But if this is the first use of the package variable it'll also allocate memory and initialize the value at runtime (which is undef if not assigned otherwise)

I.o.W. I doubt that the slot of the typeglob will be populated before, hence I'd call this a full declaration.

I suppose the terminology "declaration" stems from statically typed languages and needs to be properly redefined here.

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

update

I didn't check the implementation details, so the timing between compile and run-time might slightly differ.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-24 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found