Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by DrWhy (Chaplain)
on Apr 01, 2005 at 15:16 UTC ( [id://444213]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub insert_after_first {
        my ($ndx, $arr, $elt, $ins) = (0, @_);
        $ndx > @$arr and return while $arr->[$ndx++] ne $elt;
        splice @$arr, $ndx, 0, $ins;
    }
    
  2. or download this
    sub insert_after_first {
        my ($ndx, $arr, $elt, $ins) = (0, @_);
        $arr->[$ndx++] eq $elt and last for 0 .. @$arr;
        splice @$arr, $ndx, 0, $ins if $ndx <= @$arr;
    }
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2024-04-18 08:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found