mhyper has asked for the wisdom of the Perl Monks concerning the following question:
now I try to use $1 and $2 directly in the hash, but it does not work!?my %translation = ( "(mytag)(.*?)" => "my_new_tag", "(mytag2)(.*?)" => "my_new_tag2" ); foreach $tag(@TAGS){ foreach $key (keys %translation){ if($tag =~ /$key/gs){ $do_something_with($transaltion{$key}, $1, $2); } } }
Does anybody have a solution / workaround for this?my %translation = ( "(meintag)(.*)" => { "tag" => $1."new", "value" => $2} ); foreach $tag (@TAGS){ foreach $key (keys %translation){ if($tag =~ /$key/gs){ $do_something_with($translation{$key}->{tag}, $translation{$key}->{val +ue}); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using $1 in a hash?
by VSarkiss (Monsignor) on Feb 05, 2004 at 18:16 UTC |