Sorting Array Perl (part two) -
right, i've gotten need more, have pretty understanding on how sort array alphabetically. need sort numerically. it's syntax error near "my @test = (sort {items{$a}} <=> {items{$b}} @menu)"
had been hash 2 keys have solution, since array contains 3 categories becomes difficult me. looking along explanation possible i'm eager learn. thank you!
my @test = (sort {price{$a} <=> {price{$b}} @menu)
the issue item{$a}
. looks trying value hash item
not hash, of course.
my @test = sort { $a->{price} <=> $b->{price} } @menu;
you can sort according more 1 field well
my @test = sort { $a->{price} <=> $b->{price} or $a->{color} cmp $b->{color} or $b->{items} cmp $a->{items} # note reverse order } @menu;
Comments
Post a Comment