Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: Re: Re: Runtime Hash Variable access

by Juerd (Abbot)
on Mar 08, 2004 at 15:04 UTC ( [id://334833]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Runtime Hash Variable access
in thread Runtime Hash Variable access

What I was doing in my reply is called a sumbolic reference?

Symbolic, yes.

And that is deprecated?

No, just frowned upon.

I think it's quite a nice way of getting the value of a variable which name you don't yet know.

It's not. It requires global variables, which suck (see Coping with Scoping) and makes debugging hard. Instead, just use a hash (forget for a moment that the stash is a hash, if you knew that). Your code, using a hash and strict, would be:

use strict; my %hash; $hash{the_var_i_want} = "this is the actual value I want to get"; my $the_name = <STDIN>; #say, this would be "the_var\n" chomp $the_name; print $hash{"${the_name}_i_want"};
See also Why it's stupid to `use a variable as a variable name'.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Log In?
Username:
Password:

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

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

    No recent polls found