hello again dear monks it seems i have stumbled again on not knowing how to use switch statement properly. ok,so in response to these questions ive asked,i thank very much the people who answered me there http://perlmonks.org/?node_id=621046 http://perlmonks.org/?node_id=621054 http://perlmonks.org/?node_id=621013 and i have finally got a solution here it is:
use strict; use Switch; my $text="bla fred wilma fuck fred fuck wilma bla fred fredfred"; $text =~ s{(fred|wilma)} { my $replace_text; if($1 eq "fred") { $replace_text='wilma'; } else { $replace_text='fred'; }; $replace_text; }eg; print $text;
however to make the code i write more elegant i want to use switch instead of the if's statement but my code doesnt want to work. ive read perl documentation for switch already, no luck.
use strict; use Switch; my $text="bla fred wilma fuck fred fuck wilma bla fred fredfred"; $text =~ s{(fred|wilma)} { my $replace_text; switch($1) { case 'fred' {$replace_text='wilma'} case 'wilma' {$replace_text='fred'} }; $replace_text; }eg; print $text;
thank you
In reply to regex switch trouble by spx2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |