mnooning has asked for the wisdom of the Perl Monks concerning the following question:
I tried different variations, but could not seem to get it. I could use a key/value hash, but that seems overkill. Besides, if I added or took away options, I'd have to remember to change the hash, too. I suspect Perl has a simple answer, but I cannot see it.use strict; my $one = 0; my $two = 1; my $three = 0; my @strings = qw (one two three); my @optionsToCheck = ($one, $two, $three); foreach my $string (@strings) { print "Option $string was used\n" if ( ${"$string"} ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How can I turn a string into a variable name?
by ikegami (Patriarch) on Jan 09, 2010 at 19:13 UTC | |
|
Re: How can I turn a string into a variable name?
by chromatic (Archbishop) on Jan 09, 2010 at 19:15 UTC | |
by Anonymous Monk on Jan 09, 2010 at 20:32 UTC | |
|
Re: How can I turn a string into a variable name?
by almut (Canon) on Jan 09, 2010 at 19:27 UTC | |
by ikegami (Patriarch) on Jan 09, 2010 at 20:08 UTC | |
by almut (Canon) on Jan 09, 2010 at 20:21 UTC | |
|
Re: How can I turn a string into a variable name?
by GrandFather (Saint) on Jan 09, 2010 at 21:58 UTC |