in reply to Re: How to apply modifiers to a substitution via variable?
in thread How to apply modifiers to a substitution via variable?
use strict; use warnings; my $source = "abc"; my $find = "a"; my $replace = "x"; my %opts = ( i => 1, m => 0, s => 0, x => 0, g => 1, ); my $opts = join '', map { $opt{$_}?$_:'' } qw( i m s x ); my $re = "(?$opts:$find)"; if ($opt{g}) { $source =~ s/$re/$replace/g; } else { $source =~ s/$re/$replace/; } print $source;
|
|---|