in reply to Re: Non-greedy substitution
in thread Non-greedy substitution
There are more than one way to go old-school
use warnings; use strict; sub non_oxford_list { my ($s) = @_; my $p = rindex $s, ','; substr ($s,$p,1) = " and" if $p > -1; return $s; } use Test::More tests => 3; is non_oxford_list('A'), 'A'; is non_oxford_list('A, B'), 'A and B'; is non_oxford_list('A, B, C'), 'A, B and C';
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
|
|---|