Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Using hashref values in constant declarations.(binding)

by LanX (Saint)
on Sep 09, 2017 at 09:37 UTC ( [id://1199002]=note: print w/replies, xml ) Need Help??


in reply to Using hashref values in constant declarations.

>  However, why does this work as expected, then?
my @test = ($hashref->{ONE} .. $hashref->{TWO}); use constant GOODCONSTANT => \@test;

Short answer: that's how "binding" works!

my (like our ) has dual nature:

  • declaration happens at compile time
  • assignment at run time

Declaration means the following equally named variables in scope are "bound" to a specific "reference" (saying address would be too simplisti/C) when translated to an op tree.

GOODCONSTANT then points to that reference at compile time, but the content of @test will only be populated at run time.

Try to access content of GOODCONSTANT at compile time, and you will fail.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-19 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found