coss has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I have a question that I'd like to know why isn't possible do w +hat I pretend to do. It's reading a variable from an array to use in +an expression. Example: my @array = ('A1', 'A2', 'A3', $1, '$2'); my $message = 'If you choose a yellow car everyone will follow you!'; my $my_trigger = 'If you (.*) a (.*) car (.*) will follow you!'; if ($message =~ m/$my_trigger/g) { my $var1 = \$array[3]; my $option = \${$var1}; my $color = $2; my $whom = $3; print "option: " . $option; print "\ncolor: " . $color; print "\nwhom: " . $whom; } Why can I use inside the if $1, $2, $3 ... but can't use reading that +value from an array. The question might not make sense for lot of peo +ple, but I am curious why doesn't work... only return to me as a stri +ng and not a variable. It's possible to return as a variable?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: <p>string variable</p>
by daxim (Curate) on Jul 24, 2013 at 10:59 UTC | |
|
Re: <p>string variable</p>
by hdb (Monsignor) on Jul 24, 2013 at 10:45 UTC | |
|
Re: <p>string variable</p>
by mtmcc (Hermit) on Jul 24, 2013 at 10:47 UTC | |
|
Re: <p>string variable</p>
by AnomalousMonk (Archbishop) on Jul 24, 2013 at 14:23 UTC | |
by coss (Initiate) on Jul 24, 2013 at 16:48 UTC |