On Fri, 13 May 2005, Leif Andersson wrote: > How would you do to re-order the fields in a MARC::Record-record? > > I just needed that kind of thing and after some struggeling came up with: > > @{$record->{_fields}} = > sort { > lc($a->{_tag}) cmp lc($b->{_tag}) > } > @{$record->{_fields}}; > > > It seems to work, but I am interested in how others would address > the same problem. > > Leif
I think it's not likely to matter very much in this case, unless you need to do this to thousands of records, but ideally you'd probably want to do a Schwartzian Transform, or map-sort-map operation: @{$record->{_fields}} = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [ $_, lc($_->{_tag}) ] } @{$record->{_fields}}; This decreases the number of lc calls and _tag retrievals to once per field. Regards, Brad