Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: how to replace a matched pattern in a string with a different pattern of same length?

by wind (Priest)
on Jun 20, 2011 at 22:18 UTC ( [id://910633]=note: print w/replies, xml ) Need Help??


in reply to how to replace a matched pattern in a string with a different pattern of same length?

First calculate the longest using List::Util->max and then do a substitution.
use List::Util qw(max); use strict; use warnings; my $string = '00111100110'; my $longest = max map {length} $string =~ /(1+)/g; $string =~ s/1{$longest}/'2' x $longest/eg; print $string, "\n";
  • Comment on Re: how to replace a matched pattern in a string with a different pattern of same length?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-24 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found