Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: (golf) Collapse repetitions within a string

by kilinrax (Deacon)
on Jun 25, 2003 at 13:57 UTC ( [id://268859]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    perl -Mstrict -wlne 'while(s/(\w+?)\1+//){print$`if$`;my@L=split"(?=$1
    +)",$&;printf"%s repeated %i time%s\n",$1,$#L+1,$#L?"s":""}'
    
  2. or download this
    while(s/(\w+?)(\1+)//) {
      print $` if $`;
      my @L = split "(?=$1)", $&;
      printf "%s repeated %i time%s\n", $1, $#L+1, $#L ? 's' : ''
    }
    
  3. or download this
    perl -wlne 'while(s/(\w+?)\1+//){print$`if$`;@L=split"(?=$1)",$&;print
    +f"%s repeated %i times\n",$1,$#L+1}'
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-03-28 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found