in reply to Inserting an element into an array after a certain element
Updated to address Roy Johnson's concerns below
sub insertAfter{ use List::Util qw[ first ]; my( $aref, $before, $insert ) = @_; my $first = first{ $aref->[ $_ ] eq $before } 0 .. $#$aref ; return unless defined $first; splice @{ $aref }, ++$first, 0, $insert; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Inserting an element into an array after a certain element
by Roy Johnson (Monsignor) on Mar 31, 2005 at 19:11 UTC |