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

Re: Help making this substitutions on a strin

by GrandFather (Saint)
on Oct 21, 2022 at 03:15 UTC ( [id://11147555]=note: print w/replies, xml ) Need Help??


in reply to Help making this substitutions on a strin

Just for fun:

use strict; use warnings; my $raw = join '-', 1 .. 30; my @ranges = ([5, 10], [14, 18], [22, 27]); $raw =~ s/(\d+)/(grep {$1 >= $_->[0] && $1 <= $_->[1]} @ranges) ? 'X' +: $1/eg; my @parts = split /((?:-X)+-)/, $raw; my $sub = 'A'; for my $part (@parts) { next if $part =~ /X/; $part =~ s/\d+/$sub/g; $sub = 'A' if ++$sub eq 'C'; } print join('', @parts), "\n";

Prints:

A-A-A-A-X-X-X-X-X-X-B-B-B-X-X-X-X-X-A-A-A-X-X-X-X-X-X-B-B-B
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found