]> git.donarmstrong.com Git - biopieces.git/blobdiff - bp_bin/grab
fixed nasty bug in grab where -E and pattern 0 failed
[biopieces.git] / bp_bin / grab
index 6d2aabff4f5d55c4014202302565d3dc404c0f47..8533a4ea3bcff4f398863b6113f7819203a80f9a 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env perl -w
+#!/usr/bin/env perl
 
 # Copyright (C) 2007-2009 Martin A. Hansen.
 
@@ -26,7 +26,9 @@
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
+use warnings;
 use strict;
+use Data::Dumper;
 use Maasha::Biopieces;
 use Maasha::Common;
 use Maasha::Patscan;
@@ -35,7 +37,7 @@ use Maasha::Patscan;
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
-my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, $keys, $vals_only, $keys_only, $invert,
+my ( $options, $in, $out, $record, $keys, $vals_only, $keys_only, $invert,
      $patterns, $regex, %lookup_hash, $key, $op, $val, $found );
 
 $options = Maasha::Biopieces::parse_options(
@@ -120,6 +122,8 @@ while ( $record = Maasha::Biopieces::get_record( $in ) )
     }
 }
 
+Maasha::Biopieces::close_stream( $in );
+Maasha::Biopieces::close_stream( $out );
 
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@@ -145,7 +149,7 @@ sub grab_lookup
 
     if ( $keys )
     {
-        map { return 1 if exists $lookup_hash->{ $record->{ $_ } } } @{ $keys };
+        map { return 1 if defined $record->{ $_ } and exists $lookup_hash->{ $record->{ $_ } } } @{ $keys };
     }
     else
     {
@@ -154,7 +158,7 @@ sub grab_lookup
         }
 
         if ( not $keys_only ) {
-            map { return 1 if exists $lookup_hash->{ $record->{ $_ } } } keys %{ $record };
+            map { return 1 if defined $record->{ $_ } and exists $lookup_hash->{ $record->{ $_ } } } keys %{ $record };
         }
     }
 
@@ -178,13 +182,17 @@ sub grab_patterns
 
     # Returns boolean.
 
-    my ( $pattern );
+    my ( $pattern, $key );
 
     foreach $pattern ( @{ $patterns } )
     {
         if ( $keys )
         {
-            map { return 1 if index( $record->{ $_ }, $pattern ) >= 0 } @{ $keys };
+            foreach $key ( @{ $keys } )
+            {
+                return 0 if not exists $record->{ $key };
+                return 1 if index( $record->{ $key }, $pattern ) >= 0;
+            }
         }
         else
         {
@@ -220,7 +228,7 @@ sub grab_regex
 
     if ( $keys )
     {
-        map { return 1 if $record->{ $_ } =~ /$regex/ } @{ $keys };
+        map { return 1 if exists $record->{ $_ } and $record->{ $_ } =~ /$regex/ } @{ $keys };
     }
     else
     {
@@ -274,20 +282,13 @@ sub grab_eval
 
 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();
 }
 
 
@@ -295,4 +296,3 @@ END
 
 
 __END__
-