#!/usr/bin/perl -w my %triggers = ( 'You are (\\w+).' => '"Your status is: $1"', ); my $buff = "You are fired!"; foreach my $trigger ( keys ( %triggers ) ) { if ( $buff =~ /$trigger/ ) { #print "Memory contents of \$1: $1\n"; print eval $triggers{$trigger}; } } print "\n";
The evil string eval strips the inner double quotes of the string and interpolates $1.
In reply to Re: Using pattern match
by moritz
in thread Using pattern match
by tceng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |