0

Below is the code which actually finds a pattern in a perl array.

 my $isAvailable = grep { $_->[0] eq '12345' } {$filteredTableEntriesMap{$REPORT_PART1}} ;

But i would like to search for two patterns in two indexes at a time

 my $isWiuAvailable = grep { $_->[0] eq '12345' }     @{$filteredTableEntriesMap{$REPORT_PART1}} ;
 my $isBsAvailable  = grep { $_->[1] eq '6789' } @{$filteredTableEntriesMap{$REPORT_PART1}} ;

This is how the map is represented

 $VAR1 = {
      'REPORT PART2' => [],
      'REPORT PART1' => [
                               [
                                 '12345',
                                 '6789',                         
                               ],
                               [
                                 '343435',
                                 '315',
                               ],
                               [
                                 '00103',
                                 '000315',

                               ],
                        ]   

And i would want to match an array which has these two entries in index 1 and index 2

Thanks

1 Answer 1

2

You can combine the two conditions into one expression.

my @found = grep { $_->[0] eq '12345' && $_->[1] eq '6789' }
   @{$filteredTableEntriesMap{$REPORT_PART1}};

The stuff inside the {} for grep is basically a subroutine. You can do as much as you want in there as long as you return a true value if you want to keep $_ in your @found result.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.