in reply to Re: Inserting an element into an array after a certain element
in thread Inserting an element into an array after a certain element
You could easily fix that by adding a counter:
(as a sub)@array = map { $_ eq "c" && !$found++ ? ("c","f") : $_ } @array
sub insert_after_first { my $arr_ref = shift; my $to_insert = shift; my $insert_after_me = shift; my $found = 0; map { $_ eq $insert_after_me && !$found++ ? ( $insert_after_me, $to +_insert ) : $_ } @$arr_ref; }
--------------
"But what of all those sweet words you spoke in private?"
"Oh that's just what we call pillow talk, baby, that's all."
"But what of all those sweet words you spoke in private?"
"Oh that's just what we call pillow talk, baby, that's all."
In Section
Seekers of Perl Wisdom