Re: sorting an array of hashrefs



monkeys paw wrote:
The following is intended to sort an array of hash refs based on
id_type. It is not working however. Does anyone know why?

use Data::Dumper;

our %datatype_sort = (
bill => 0,
reg => 10,
);


my @ary = (
{id_type => 'reg', id => 'KY200616813'},
{id_type => 'bill', id => 'CA2005000A5'},
{id_type => 'bill', id => 'CA2005000A250'},
);

my @x = sort _sortval_datatype @ary;

print Dumper(\@x);

sub _sortval_datatype {
my($av, $bv) = @_;
return $datatype_sort{$av->{id_type}} <=>
$datatype_sort{$bv->{id_type}};
}


sub _sortval_datatype {
return $datatype_sort{$a->{id_type}} <=> $datatype_sort{$b->{id_type}};
}



John
--
use Perl;
program
fulfillment
.



Relevant Pages

  • Re: Select all when control gets focus
    ... Remote Programming and Training ... Private Sub Phone_Click ... since you are not storing the symbols, I hard-coded numbers in -- since the length in the control is> len... ... Bill Fischer ...
    (microsoft.public.access.formscoding)
  • Re: Run Macro during slide show
    ... tried to combine bills code that does work with what i thought would change ... Sub redx ... "Bill Dilworth" wrote: ... only while in edit view. ...
    (microsoft.public.powerpoint)
  • RE: Next record on parent form after update of child form
    ... The code that you are using to move to the next record, you mantion that you ... "Bill" wrote: ... > After adding/editing a record to a sub/sub form I'd like to move to the next ... > Are there special considerations when moving back from sub to main. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Move through a list box.
    ... Created a text box called txtBillHdn bound to the Bill field (the list box ... Private Sub btntstLst_Click ... First set the value of the list box to the newly ... the list selection is moving up and down. ...
    (microsoft.public.access.formscoding)
  • Re: Inserting Picture from File using VBA
    ... Thanks Bill. ... Sub Main ... 'Create a FileDialog object as a File Picker dialog box. ... Dim vrtSelectedItem As Variant ...
    (microsoft.public.powerpoint)