Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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
Domain Nodelet?
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 lurking in the Monastery: (6)
As of 2023-03-22 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (60 votes). Check out past polls.

    Notices?