Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: Using pattern match

by mreece (Friar)
on Aug 11, 2007 at 05:50 UTC ( #631932=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://631932]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2021-01-27 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?