Forum Moderators: coopster & phranque

Message Too Old, No Replies

Sorting hashes by different values

probably a really easy fix

         

molecularr

2:15 pm on Jun 10, 2004 (gmt 0)

10+ Year Member



Hi everyone.

I'm working on a pretty simple script that reads a bunch of txt files, turns those files' contents into hashes, and then prints an html page of those results.

Pretty basic stuff.

I can sort it by the file names pretty easily, but I need to figure out a way to sort the result hashes by different key/values. Basically it's sorting bibliographical information, so I would need it to do something like sort by $hash{title} or $hash{format}.

Is there any easy way to do this?

Thanks,
m

volatilegx

3:27 pm on Jun 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might find this page useful

[devdaily.com...]

[edited by: jatar_k at 5:42 pm (utc) on June 10, 2004]
[edit reason] linked it up [/edit]

SeanW

1:31 pm on Jun 11, 2004 (gmt 0)

10+ Year Member



You can pass a custom sort routine to sort

[perldoc.com...]

ie

sort {$a->{title} <=> $b->{title}} keys (%hash)

(as an anon sub, or pass the name of a function to break it out)

Sean

molecularr

5:01 am on Jun 14, 2004 (gmt 0)

10+ Year Member



Sean, volatile,

Both of your suggestions got me thinking towards a solution I'm pretty happy with.

Thanks,
molecularr