X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fsort_records;h=af8edbc8c189489eb1a32d65043af37d1551f32a;hb=5de6112b70b59420b245ce636a8b2e3c90acbe00;hp=32d59dfc38c6e337b25d815f0375ba9487f70c85;hpb=ce9afe503d79816a65b6d063df94a09f0e73ef5a;p=biopieces.git diff --git a/bp_bin/sort_records b/bp_bin/sort_records index 32d59df..af8edbc 100755 --- a/bp_bin/sort_records +++ b/bp_bin/sort_records @@ -1,4 +1,4 @@ -#!/usr/bin/env perl -w +#!/usr/bin/env perl # Copyright (C) 2007-2009 Martin A. Hansen. @@ -26,6 +26,7 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +use warnings; use strict; use Maasha::Biopieces; @@ -33,7 +34,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 ( $options, $in, $out, @keys, $key, @sort_cmd, $sort_str, $sort_sub, @records, $record, $i, $ok ); $options = Maasha::Biopieces::parse_options( [ @@ -57,8 +58,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; @@ -76,26 +88,22 @@ else } } +Maasha::Biopieces::close_stream( $in ); +Maasha::Biopieces::close_stream( $out ); + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< BEGIN { - $run_time_beg = Maasha::Biopieces::run_time(); - - Maasha::Biopieces::log_biopiece(); + Maasha::Biopieces::status_set(); } END { - Maasha::Biopieces::close_stream( $in ); - Maasha::Biopieces::close_stream( $out ); - - $run_time_end = Maasha::Biopieces::run_time(); - - Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options ); + Maasha::Biopieces::status_log(); } @@ -103,4 +111,3 @@ END __END__ -