in reply to regex switch trouble
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex switch trouble
by spx2 (Deacon) on Jun 14, 2007 at 01:37 UTC | |
by graff (Chancellor) on Jun 14, 2007 at 02:07 UTC | |
by blazar (Canon) on Jun 24, 2007 at 10:04 UTC | |
by graff (Chancellor) on Jun 24, 2007 at 17:35 UTC | |
by blazar (Canon) on Jun 24, 2007 at 19:25 UTC | |
by ikegami (Patriarch) on Jun 14, 2007 at 14:42 UTC |