Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: creating dynamically named 'my' variables

by rrwo (Friar)
on Mar 01, 2002 at 04:42 UTC ( [id://148477]=note: print w/replies, xml ) Need Help??


in reply to creating dynamically named 'my' variables

Wait a minute! You want to create variables given names by the user?!?!! That's pretty dangerous, unless you trust the user wholeheartedly.

Use a hash instead.

You can use symbolic references to do this:

my $bar="fred"; no strict refs; $$bar="ethel"; print $fred, "\n"; print $$bar, "\n";

but it doesn't work as a "my variable". In part I think because the scope is limited to within the eval. Ooutside the eval, the variable goes way.

I really don't recommend you do this, though.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-24 20:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found