Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: loop iterator in a string

by BillKSmith (Monsignor)
on Sep 27, 2021 at 18:49 UTC ( #11137063=note: print w/replies, xml ) Need Help??


in reply to loop iterator in a string

This is pretty close to what you want. Use eval to evaluate the operators in the string.
use strict; use warnings; my $arr=[1,2,3,4,5,6,7]; my $loop="2,4..5"; splice @$arr,$_,0,999 foreach(eval $loop); $, = ' '; print @$arr

OUTPUT:

1 2 999 3 999 999 4 5 6 7
Bill

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2021-12-05 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (31 votes). Check out past polls.

    Notices?