in reply to Re: dynamic regex variable
in thread dynamic regex variable
Here's an alternative that matches your specs without using eval:
sub check_logs { my $regx_template = shift(@_); my @clients = qw(abc def hij); foreach my $client (@clients) { my $regx = $regx_template; $regx =~ s/\\\$(?:client\b|{client})/$client/g; print($regx, "\n"); } } foreach my $regx_template ( qr/pre-\$client-post/, qr/foo-\$client-bar/, qr/moo\${client}moo/, ) { check_logs($regx_template); } __END__ output ====== (?-xism:pre-abc-post) (?-xism:pre-def-post) (?-xism:pre-hij-post) (?-xism:foo-abc-bar) (?-xism:foo-def-bar) (?-xism:foo-hij-bar) (?-xism:mooabcmoo) (?-xism:moodefmoo) (?-xism:moohijmoo)
|
|---|