Sunday, 15 August 2010

Sorting Array Perl (part two) -


OK, so I've got some help but need something else, I'm pretty good about sorting an array Understand alphabetically But now I need to sort it numerically. This is probably a syntax error with " my @ test = (sort {object {$ a}} & lt; = & gt; {item {$ b}} @ menu" "

If it had been a hash with two keys then I would have solved, but there are three categories in this array, so it becomes difficult for me to have some help with an explanation as clearly as possible Looking forward as I am keen to learn thanks!

  my @test = (sort {value {$ a} & lt; = & gt; {value {$ b}} @ menu)  

issue item {$ a} It looks like you have hash items Trying to get some value from, which is definitely not a hash

  my @test = sort {$ a- & gt; {Price} & lt; = & Gt; $ B- & gt; {Value}} @ menu;  

You can sort by more than one field

  my @test = sort {$ a-> gt; {Price} & lt; = & Gt; $ B- & gt; {Value} or $ a-> {Color} cmp $ b- & gt; {Color} or $ b- & gt; {Item} cp $ a- & gt; {Item} # note reverse order} @ menu;  

No comments:

Post a Comment