Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Golf: Replacing part of a string with "*"

by ikegami (Patriarch)
on Aug 18, 2006 at 15:28 UTC ( [id://568189]=note: print w/replies, xml ) Need Help??


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
        Congrats to him; I didn't look that far into the replies.

        Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
        How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://568189]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found