Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: loop iterator in a string

by tybalt89 (Monsignor)
on Sep 27, 2021 at 21:39 UTC ( [id://11137071]=note: print w/replies, xml ) Need Help??


in reply to loop iterator in a string

For the evalphobic...

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11137057 use warnings; my $arr=[1,2,3,4,5,6,7]; my $loop="2,4..5"; splice @$arr,$_,0,999 foreach map { /\.\./ ? $` .. $' : $_ } split /,/ +, $loop; use Data::Dump 'dd'; dd $arr;

Outputs:

[1, 2, 999, 3, 999, 999, 4 .. 7]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-24 07:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found