Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: use strict

by gjb (Vicar)
on Jun 01, 2004 at 13:01 UTC ( #358022=note: print w/ replies, xml ) Need Help??


in reply to use strict

Why not consider using a hash? If I understand you correctly you want to assign to variables that have names you don't now in advance.

use strict; my @interests = ( "foo", "bar", "blah"); my %hash; foreach (@interests) { $hash{$_} = "My interest is $_"; } foreach (keys %hash) { print "$hash{$_}\n"; }

Hope this helps, -gjb-

Update: Thanks dragonchild for pointing out a typo (%hash rather than @interests in the last foreach)


Comment on Re: use strict
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2015-07-07 07:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls