Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by RazorbladeBidet (Friar)
on Mar 31, 2005 at 18:58 UTC ( #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
Node Status?
node history
Node Type: note [id://443929]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2020-10-24 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (242 votes). Check out past polls.

    Notices?