in reply to Variable/multiple matches using grep
Is there a way to limit the match as /^$one$/ would work for example?
Most likely, yes. However, you've not shown what the expected values are for the data that you're matching against, nor what qualifies as a match, nor how you tell when two & three are empty.
Personally, I use something where an indentifier may be made up of 4 parts ... (provider, source, instrument, detector), and they're identified by strings of the format "PROV.SOURCE.INST.DET", each of the individual identifiers is alphanumeric:
my $pattern = qr( '^'. ( join '\.', map { defined($_) ? $_ : '[^.]*' } @query{ qw( provider source instrument detector ) } ). '$' ); my @matches = grep { $_ =~ m/$pattern/ } @data;
Note -- I'm using '[^.]*' as opposed to '[^.]+', as not all of the identifiers have all 4 items populated, and would be empty for those slots.
|
|---|