]> 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 1be030a34e1ab4b451f386d5ad8443a3959436f9..8533a4ea3bcff4f398863b6113f7819203a80f9a 100755 (executable)
@@ -26,7 +26,9 @@
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
+use warnings;
 use strict;
+use Data::Dumper;
 use Maasha::Biopieces;
 use Maasha::Common;
 use Maasha::Patscan;
@@ -147,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
     {
@@ -156,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 };
         }
     }
 
@@ -180,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
         {
@@ -222,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
     {