Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I would like to use the ".." as a loop operator but in a string. Is there any simple perl-ish way I can accomplish this? For some reason, I thought perl would support this, but it doesn't.
I would like to use the ".." as a loop operator but in a string. Is there any simple perl-ish way I can accomplish this? For some reason, I thought perl would support this, but it doesn't.
my $arr=[1,2,3,4,5,6,7]; my $loop="2,4..5"; splice @$arr,$_,0,999 foreach($loop);
I want $arr to be [1, 2, 999, 3, 999, 999, 4, 5, 6, 7]. This works fine if you pass in 2,4..5 instead of "2,4..5". I notice that '2', '4'..'5' will also work, but when the .. operator is within string, it does not.
Thank you for your time!Michael
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: loop iterator in a string
by haukex (Archbishop) on Sep 27, 2021 at 18:46 UTC | |
by Anonymous Monk on Sep 28, 2021 at 13:20 UTC | |
Re: loop iterator in a string
by tybalt89 (Monsignor) on Sep 27, 2021 at 21:39 UTC | |
Re: loop iterator in a string
by LanX (Saint) on Sep 27, 2021 at 18:33 UTC | |
by Anonymous Monk on Sep 27, 2021 at 18:41 UTC | |
by haukex (Archbishop) on Sep 27, 2021 at 18:54 UTC | |
by LanX (Saint) on Sep 27, 2021 at 21:12 UTC | |
by haukex (Archbishop) on Sep 28, 2021 at 10:23 UTC | |
| |
Re: loop iterator in a string
by BillKSmith (Monsignor) on Sep 27, 2021 at 18:49 UTC | |
Re: loop iterator in a string
by LanX (Saint) on Sep 28, 2021 at 15:45 UTC |
Back to
Seekers of Perl Wisdom