in reply to How can I change substitution options within a program?
For imsx, you can use (?switches:pattern). For g, you'll have to use an if.
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 { $opts{$_}?$_:'' } qw( i m s x ); my $re = "(?$opts:$find)"; if ($opts{g}) { $source =~ s/$re/$replace/g; } else { $source =~ s/$re/$replace/; } print $source;
Update: Fixed where %opts was referenced as %opt.
|
|---|