http://qs321.pair.com?node_id=631932


in reply to Re^3: Using pattern match
in thread Using pattern match

you can capture the list yourself, and then do substitutions from it.
#!/usr/bin/perl -w my %triggers = ( 'You are (\\w+).' => 'Your status is: $1', ); my $buff = "You are fired!"; foreach my $trigger ( keys ( %triggers ) ) { if ( my @captures = $buff =~ /$trigger/ ) { # $1 == $captures[0], ..etc my $response = $triggers{$trigger}; $response =~ s/\$([0-9]+)/$captures[$1-1]/g; print $response; } } print "\n";

Replies are listed 'Best First'.
Re^5: Using pattern match
by tceng (Novice) on Aug 11, 2007 at 22:08 UTC
    Splendid!