in reply to Inserting an element into an array after a certain element
Output:#!/usr/bin/perl @a=("a","b","c","b","a"); $targ="b"; $ins="d"; THINGY: foreach(@a) { $_ =~ $targ && do { splice(@a,$i,1,($_, $ins)); last THINGY }; $i++; }; print join ", ", @a; print "\n"
It's not entirely cool; it does take an iterator, which I accept is fairly cheesy, but it does the job in a single foreach() that probably won't even make it to the end of the array.a, b, d, c, b, a
|
|---|