in reply to Golf: Replacing part of a string with "*"
my $string = '5424123412345678'; substr$_,0,-4,'*'x(length()-4)for$string; # 41 print $string;
my $string = '5424123412345678'; s/(?!.{0,4}$)./*/g for$string; # 30 print $string;
Update: More readable than the previous:
my $string = '5424123412345678'; $string=~s/(?!.{0,4}$)./*/g; # 28 print $string;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Golf: Replacing part of a string with "*"
by japhy (Canon) on Aug 18, 2006 at 16:04 UTC | |
by ikegami (Patriarch) on Aug 18, 2006 at 16:10 UTC | |
by japhy (Canon) on Aug 19, 2006 at 00:38 UTC |