In complement to Corion's answer: Re: sorting hash by a certain value (that it is in an array)
Here is an example. You can use more complexe sorting method (see commented line: lc(...) cmp lc(...)) and optimized it with The Orcish Maneuver.#!/usr/bin/env perl use strict; use warnings; my %books=( '34' => ['enlgish', 'dani M. rod', 54], '24' => ['spanish', 'ramk rovale', 41], '54' => ['enlgish', 'bob falicas', 17], ); my @sorted_books = sort { $books{$a}->[1] cmp $books{$b}->[1] #lc($books{$a}->[1]) cmp lc($books{$b}->[1]) } keys %books; print "@sorted_books";
Update: print sorted books
for my $book_id (@sorted_books) { print "$book_id: ",join ", ",@{ $books{$book_id} }; print "\n"; }
In reply to Re: sorting hash by a certain value (that it is in an array)
by brx
in thread sorting hash by a certain value (that it is in an array)
by gooyava
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |