in reply to Using pattern match
#!/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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using pattern match
by tceng (Novice) on Aug 10, 2007 at 12:02 UTC | |
by FunkyMonk (Bishop) on Aug 10, 2007 at 12:26 UTC | |
by tceng (Novice) on Aug 10, 2007 at 13:57 UTC | |
by akho (Hermit) on Aug 10, 2007 at 14:15 UTC | |
by tceng (Novice) on Aug 10, 2007 at 14:50 UTC | |
by akho (Hermit) on Aug 10, 2007 at 15:46 UTC | |
by Anonymous Monk on Aug 10, 2007 at 14:37 UTC | |
by tceng (Novice) on Aug 10, 2007 at 15:21 UTC |