I don't know why the switch is not valid there, but anything that complex should be hoisted out of the replacement anyway. This works:
use strict; use warnings; use Switch; my $text = 'bla fred wilma fuck fred fuck wilma bla fred fredfred'; sub replace_it { switch( $_[0] ) { case 'fred' { return 'wilma' } case 'wilma' { return 'fred' } die; }; } $text =~ s{(fred|wilma)}{replace_it($1)}eg; print $text;
In reply to Re: regex switch trouble
by Util
in thread regex switch trouble
by spx2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |