From 1779ce0eb455423f3d63a313073d3ca837094ce8 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Thu, 4 Jun 2009 13:43:56 +0000 Subject: [PATCH] fixed bug in sort_records git-svn-id: http://biopieces.googlecode.com/svn/trunk@473 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/sort_records | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bp_bin/sort_records b/bp_bin/sort_records index 32d59df..9c551b0 100755 --- a/bp_bin/sort_records +++ b/bp_bin/sort_records @@ -33,7 +33,7 @@ use Maasha::Biopieces; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $run_time_beg, $run_time_end, $options, $in, $out, @keys, $key, @sort_cmd, $sort_str, $sort_sub, @records, $record, $i ); +my ( $run_time_beg, $run_time_end, $options, $in, $out, @keys, $key, @sort_cmd, $sort_str, $sort_sub, @records, $record, $i, $ok ); $options = Maasha::Biopieces::parse_options( [ @@ -57,8 +57,19 @@ foreach $key ( @{ $options->{ "keys" } } ) $sort_str = join " or ", @sort_cmd; $sort_sub = eval "sub { $sort_str }"; # NB security issue! -while ( $record = Maasha::Biopieces::get_record( $in ) ) { - push @records, $record; +while ( $record = Maasha::Biopieces::get_record( $in ) ) +{ + $ok = 1; + foreach $key ( @{ $options->{ "keys" } } ) + { + if ( not exists $record->{ $key } ) + { + $ok = 0; + last; + } + } + + push @records, $record if $ok; } @records = sort $sort_sub @records; -- 2.39.5