Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Inserting an element into an array after a certain element

by RazorbladeBidet (Friar)
on Mar 31, 2005 at 18:58 UTC ( [id://443929]=note: print w/replies, xml ) Need Help??


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:
@array = map { $_ eq "c" && !$found++ ? ("c","f") : $_ } @array
(as a sub)
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."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-03-29 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found