D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] perl question - how to sort arrays of hashes? [SOLVED]

 

On Fri, 01 Feb 2008 18:52:03 +0000, morgadave@xxxxxxxxxxxxxx
wrote:

>
>
>Posted by "dave morgan" <morgadave@xxxxxxxxxxxxxx>
>
>
>I am trying to load EXIF data from jpegs into some sort of array, and I want it to 
>end up sorted by timestamp, but I can't get the sort to work right.
>
>Any suggestions on how to sort, or if I need a different data structure?
>
>more background in the Man page at http://www.morgad.co.uk/csv2kml-man.html
>
>
>my @sorted;
>## //FIXME// what to put here??
>@sorted = sort { $jpeg[$a]{mtime} <=> $jpeg[$b]{mtime} };
>

turns out I was basically right from the start ..

@sorted = sort { $a->{mtime} <=> $b->{mtime} } @jpeg;

but all the 'attempt to modify read-only value' errors that had
me going round in circles were caused by my arrays going from
1..n, not 0..(n-1), and the undefined entries for index 0 stopped
the sort from working :-/

(the man page now includes changelog and source download links)

Dave
-- 
http://www.morgad.co.uk/index.html 
DP: http://www.pgdp.net   NTP: http://www.pool.ntp.org
L&B: http://www.lynton-rail.co.uk

-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html