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

the eval() solution would work in the above case, but be advised that this approach is even eviler than (string) eval() used on its own. this is because code can be evaluated at run time both in eval() and in the extended regex pattern (?{{ code... }}).

see the subject of taint checking and perlsec for more horrific details.

Replies are listed 'Best First'.
Re^4: Using pattern match
by tceng (Novice) on Aug 10, 2007 at 15:21 UTC
    Thanks for your feedback, it's very interesting and appreciated.
    The script will run as server and therefore I'd like it to tun in tainted mode, so I figured out another way to do things:
    #!/usr/bin/perl -w -T use strict; # builtin triggers my %triggers; # add triggers from params my $trigger_name = shift @ARGV; my $trigger_action_str = shift @ARGV; $triggers{$trigger_name} = $trigger_action_str; my $buff = "You are fired!"; foreach my $trigger ( keys ( %triggers ) ) { if ( $buff =~ /$trigger/ ) { my $c1 = $1; my $txt = $triggers{$trigger}; $txt =~ s/\$1/$c1/g; print $txt; } }
    Yes, that's not elegant for I should save each memory container $1, $2, and so on to be general enough, but at least I can run it in tainted mode:
    perl -T triggers4.pl "You are (\w+)." "Your status: $1"

    So I get:
    Your status: fired

    Cheers,
    tceng