On Jun 20, Kevin Old said: >I have a hash with the key being the field name and the value being the >order in which the field is to be displayed.....like below: > >%order = ( > DATE => '1', > CPP => '2', > ESN => '3', > BTS => '4' > ); > >I'm receiving an array that would look something like this: > >@to_be_ordered = qw(CPP BTS DATE); > >What I'd like to do, is sort @to_be_ordered based on the ordering scheme >defined in %order. Notice that ESN is missing....I'd like to be able to >keep it in order even if some are missing. > >I've looked at the sort and map functions and can't quite figure out how >to manipulate the array into the way I need it.
It'd be good to show your attempts, even if they are broken. The problem is not all that difficult; merely supply sort() with a block specifying the comparison to make. @sorted = sort { $order{$a} <=> $order{$b} } @to_be_ordered; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]