in reply to Perl/Unix question; returning grep as a boolean and returning a match

Based on your comments this may work (UNTESTED):

my $y = 'aaa'; my $unzip = 'zcat'; my $dir = '<PATH>'; opendir my $DH, $dir or die "Cannot open directory '$dir' because: $!" +; foreach my $path ( map "$dir/$_", readdir $DH ) { my ( $exact, $not_exact ); open my $PIPE, '-|', $unzip, $path or die "Cannot open pipe from ' +$unzip' because: $!"; while ( <$PIPE> ) { if ( /$y/ ) { $exact = 1; last; } if ( /($y)/i ) { $not_exact = $1; } } close $PIPE or warn $! ? "Error closing '$unzip' pipe: $!" : "Exit status $? from '$unzip'"; if ( ! $exact && defined $not_exact ) { $y = $not_exact; } }
  • Comment on Re: Perl/Unix question; returning grep as a boolean and returning a match
  • Download Code