in reply to not able to replace the element in the middle of the string
TIMTOWTDI
#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 3; my $have = 'aabbccddaaffddnnaa'; my $want = 'aabbccddeeffddnnaa'; my $aa = $have; # perldoc perlre $aa =~ s/daaf/deef/; is ($aa, $want, 'Match explicit surrounds'); # perldoc perlre $aa = $have; $aa =~ s/(.)aa(.)/$1ee$2/; is ($aa, $want, 'Match non-terminal surrounds'); # perldoc -f substr $aa = $have; substr ($aa, length($aa)/2 - 1, 2, 'ee'); is ($aa, $want, 'Replace middle 2 chars of even-length string');
Since you've given no algorithm to determine what to replace choose whichever suits.
|
|---|