[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] sorting arrays




17 Jun 1999, Ronald J Kimball wrote:
 >>Well, someone suggested using hashes to solve this problem of sorting a
 >>file, and I'd like to see just what they had in mind!

Guys -

What I had in mind was not to use an array at all, but to just read the
values into a hash and use them from there.  I'm presuming that Alan's full
script will do more than simply print the list of sorted names, and that
there are probably more fields involved for the people than just their
names.  So a hash seems (to this newbie) like the natural perlish-way to
store such data.

This approach does lose some of its simplicity since the name pairs are not
unique; we'd need to introduce a generation-number or some other ordinal to
distinguish same-name people.  So you might store the information for a
person by:

    $Person{"$lastname/t$firstname/t$generation"} = ($attrib1, $attrib2,
... ) ;

Or you might prefer a string of nested anonymous hashes:

    $Person->{$lastname}->{$firstname}->{$generation} = ($attrib1, ... ) ;


I wouldn't say I prefer "brute force" to "elegance", but I do find code is
easier to maintain or share if it uses "natural, straightforward"
constructs wherever possible.


didn't mean to start a flame war,
rkm

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org