Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 ( #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
Node Status?
node history
Node Type: note [id://910633]
help
Chatterbox?
[thezip]: Ooops... I lied. I guess Cygwin is back. I'll just do a tail -f instead. Better. Sorry for the noise.
[Corion]: Once more, I'm looking for a sane client-side framework, but I guess these don't exist. Everything I look at either uses a weirdo home-grown templating language (like Angular in all its incarnations) or uses weirdo Javascript incarnations (like ...
[Corion]: ... Inferno.js, which uses ES2015) or uses some horrible amount of Javascript infrastructure before you can even render a single file.
[Corion]: I'd really like to create a dynamic frontend for my Google Keep clone, but so far, all the templating solutions seem to bring their own template language or require me to hand-code everything in (their own flavour of) Javascript. I'd like something ...
[Corion]: ... that can use templates from the HTML (via <script language="text/ template">... my template ...</script> and otherwise gets out of my way. But it seems that is not how the Javascript world is, currently :-/

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2017-03-27 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (321 votes). Check out past polls.