Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by tall_man (Parson)
on Apr 01, 2005 at 00:52 UTC ( #444037=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub insert_after_first {
       my ($arr, $find, $insert) = @_;
    ...
       my ($pos) = grep { $arr->[$_] eq $find and !$found++ } 0..$#$arr;
       splice @$arr, $pos+1, 0, $insert if $found;
    }
    
  2. or download this
    sub insert_after_first {
       my ($arr, $find, $insert) = @_;
       my ($pos) = grep { $arr->[$_] eq $find } 0..$#$arr;
       splice @$arr, $pos+1, 0, $insert if defined($pos);
    }
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2019-11-22 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (113 votes). Check out past polls.

    Notices?