http://www.perlmonks.org?node_id=996195


in reply to Linked list in Perl

Linked list is best if you need to add at the end and pick from beginning. If you want to insert/remove elements in the middle you have to travel from the beginning and if you are at desired element C (after which you want to insert new element N) just copy link to next element from C to N, set link to next element in C to N and you are done. So you want to change

C -> nextElem

to

C -> N -> nextElem