in reply to Replace the last letter
#!/usr/bin/perl use strict; use warnings; my $tofind="s"; my $replacement="X"; my $variable="snaskes"; print "Before: $variable\n"; $variable =~ s/$tofind[^$tofind]*$/$replacement/; # OR # $variable =~ s/$tofind(?![$tofind])$/$replacement/; print "After: $variable\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Replace the last letter
by hv (Prior) on Oct 08, 2004 at 15:10 UTC |