in reply to Linked list in Perl

Just use an array, and splice to add the new element e.g. to add something after position 5:
+% perl -de0 Loading DB routines from perl5db.pl version 1.32 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 0 DB<1> @ar = 'a' .. 'h' DB<2> x \@ar 0 ARRAY(0x288c320) 0 'a' 1 'b' 2 'c' 3 'd' 4 'e' 5 'f' 6 'g' 7 'h' DB<3> @slice = @ar[6 .. -1] DB<4> splice @ar, 6, @slice, 11, @slice DB<5> x \@ar 0 ARRAY(0x288c320) 0 'a' 1 'b' 2 'c' 3 'd' 4 'e' 5 'f' 6 11 7 'g' 8 'h' DB<6>

Also see How do I handle linked lists?

Replies are listed 'Best First'.
Re^2: Linked list in Perl
by Anonymous Monk on Sep 28, 2012 at 12:46 UTC

    To insert , use length zero

    perl -deep oading DB routines from perl5db.pl version 1.33 ditor support available. nter h or `h h' for help, or `perldoc perldebug' for more help. ain::(-e:1): ep DB<1> @f=a..f; DB<2> x\@f ARRAY(0xe2b154) 0 'a' 1 'b' 2 'c' 3 'd' 4 'e' 5 'f' DB<3> splice @f, 3,0, P; DB<4> x\@f ARRAY(0xe2b154) 0 'a' 1 'b' 2 'c' 3 'P' 4 'd' 5 'e' 6 'f' DB<5> q