Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: explanation of constant syntax?

by meonkeys (Chaplain)
on Mar 20, 2004 at 17:57 UTC ( [id://338329]=note: print w/replies, xml ) Need Help??


in reply to •Re: explanation of constant syntax?
in thread explanation of constant syntax?

I understand that the bareword FOO inside the parens is similar to when it's inside @{[...]} because it causes the subroutine created by the constant pragma to be called rather than FOO to simply be used as a hash key.

Would you elucidate on why this happens or point me to the right perldoc to read on this subject?

---
"A Jedi uses the Force for knowledge and defense, never for attack."

Replies are listed 'Best First'.
•Re: Re: explanation of constant syntax?
by merlyn (Sage) on Mar 20, 2004 at 18:22 UTC
    Well, just break it apart:
    [ ... ]
    creates an arrayref pointing to its contents, in this case FOO (not quoted, so we get the constant value). And then:
    @{ ... }
    dereferences the enclosed value as if it were an array reference. So essentially, this is the hard way to say:
    ( ... )
    between the two of them, except that it also interpolates within a double-quoted string. That's how I stumbled across this in the first place: how to evaluate a value inside a double-quoted string. I wrote about it in a CLP posting early in the Perl5 days, and the meme stuck and is still being used in other places.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-19 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found