d4vis has asked for the wisdom of the Perl Monks concerning the following question:
The tutorial's solution is the following:$_='Us ? The bus usually waits for us, unless the driver forgets us.';
This works, but when I got to thinking about it...$_='Us ? The bus usually waits for us, unless the driver forgets us.'; print "$_\n"; s/\b([Uu])s(\W)/chr(ord($1)-1).hem.$2/eg; print "$_\n";
also works and seems simpler to a newbie like me. I guess I'm just wondering if there's something about substitutions that I don't know yet which makes the simpler solution 'bad practice' or sloppy programming? I get the sense that the tutorial chose the solution it did based on something I don't yet know about regex's, but I can't figure out what that is.$_='Us? The bus usually waits for us, unless the driver forgets us.'; print "$_\n"; s/\bus\b/them/ig; print "$_\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Ovid) Re: a simple substitution question
by Ovid (Cardinal) on Aug 21, 2000 at 22:31 UTC | |
by tilly (Archbishop) on Aug 21, 2000 at 22:39 UTC | |
|
RE (tilly) 1: a simple substitution question
by tilly (Archbishop) on Aug 21, 2000 at 22:19 UTC |