in reply to Re: Recursion, tree parsing. in thread Recursion, tree parsing.
Some of those data structures that you never notice,
the reason that you never notice them being coded up
in Perl is because they don't have to be coded up by
hand; Perl has stuff that accomplishes the same thing
without a lot of extra work. Linked lists are a perfect
example. Nobody _needs_ to code up linked lists in Perl,
because Perl isn't so primitive as C. Perl isn't Lisp, but
it has more builtin list-processing stuff than C. C programmers find them using linked lists sometimes when they don't know the length of an array at compile time; we don't need that sort of kludge in Perl because
arrays are dynamic in length. We also don't need them for
most of the other things they're used for in C (e.g., inserting
items in the middle), because again Perl already has enough
power to do stuff like that without the extra help. Linked lists are also used to implement stacks sometimes, but Perl just uses arrays for that. That's what we have push and pop for, after all.
Trees you will occasionally see in Perl, though; I think
there are a CPAN module or two for working with them. But
there is one major use of trees that you won't see much in
Perl: they're often used for sorting and searching, and Perl programmers
are more likely to use hashes for that, or the builtin sort
primitive, or both together, or throw it all in a database
and use DBI. But trees are generally useful, so you will
see them used sometimes for other things, as well as directed
and undirected graphs occasionally
|