Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: How to implement Linked List

by Hofmator (Curate)
on Dec 18, 2006 at 12:42 UTC ( #590419=note: print w/replies, xml ) Need Help??

in reply to How to implement Linked List

I must agree with rinceWind, I don't see the need for linked lists in your example.

For further reference, chapter 3 of Mastering Algorithms with Perl explains how to implement linked lists in Perl. The following code is an example out of the book:

#!/usr/bin/perl $list = $tail = undef; foreach (1..5) { my $node = [ undef, $_ * $_ ]; $list = undef; $tail = \$list; foreach (1..5) { my $node = [ undef, $_ * $_ ]; $$tail = $node; $tail = \$node->[NEXT]; } }

-- Hofmator

Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://590419]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2017-01-19 03:29 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (167 votes). Check out past polls.