Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Ref to a list not being equivalent to a list of refs to each element

by davido (Cardinal)
on Jun 22, 2006 at 16:55 UTC ( [id://556950]=note: print w/replies, xml ) Need Help??


in reply to Ref to a list not being equivalent to a list of refs to each element

That's an interesting quirk you've found.

This discussion does present the opportunity to discuss the creation of constants. There's always the constant pragma, but it makes interpolation difficult and syntax confusing. There's your typeglob method, but the fact that *variable = \'value'; creates a sort of immutable constant is itself simply a side effect, easily forgotten unless one brushes up on the POD periodically.

How about the use Readonly; solution?

use strict; use warnings; use Readonly; Readonly my $VAR => 'value'; #......

It's clear, it states what it does explicitly, and it interpolates properly. Are there negatives to this approach? The ones I can think of are that not everyone will have Readonly.pm installed (but it's easy), and also, unless Readonly::XS.pm is also installed, the new readonly variables will incur a slight performance hit.


Dave

Log In?
Username:
Password:

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

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

    No recent polls found