Jc wrote:
> I just had a friend explain in some little detail about linked lists
> in C using structures.
>
> How would such a thing be done with Perl?  This may help me
> understand C's version a little better.
>
> If you need more information than this, I can provide it...I think :)

Yes, more information would be nice. In particular C has no built-in
linked-list capability and I would like to see what sort of
implementation you're wanting to emulate.

The most common way to implement linked lists in C is by pointers.
Something like:

    struct link {
        int data;
        struct tag *next;
    } a, b;
    a.data = 1;
    a.next = &b;
    b.data = 2;

and so on. Perl has references, which are similar to C pointers
except that you can't do arithmetic on them (to find the address
of a given array element given its base address, say) so you could
write something equivalent like this:

    my (%a, %b);

    $a{data} = 1;
    $a{next} = \%b;

    $b{data} = 2;

But exactly how the list is implemented depends on what
functionality you need.

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to