Handling linked lists in Perl is not the same as in C. You can emulate them with arrays and manipulate them by using Perl's array functions.


Create a list:                       my @list = ();
Clear the list:                      @list = ();
Add an $item:                        push @list, $item;
Remove an $item:                     $item = pop @list;
Add an $item to the other end:       unshift @list, $item;
Remove an $item from the other end:  $item = shift @list;
Get its size:                        $size = scalar( @list );
Retrieve the first $item:            $item = $list[0];
Retrieve the last $item:             $item = $list[-1];
Retrieve $n items from position $i:  @items = @list[ $i .. $i+$n-1 ];
Remove $n items from position $i:    @items = splice( @list, $i, $n );
Insert @items at position $i:        splice( @list, $i, 0, @items );
Reverse the list:                    @list = reverse @list;
Rotate the list:                     push @list, shift @list;
Reverse rotate the list:             unshift @list, pop @list;


--

Just my 0.00000002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to