I don't like how you keep calling many things elements :)
#!/usr/bin/perl -- use strict; use warnings; use List::AllUtils qw' indexes '; use Data::Dump qw' dd '; my @options = ( "A-B-F-G-H-K-M", "A-E-G-H-L", "A-C-E-G-H-J-L", "B-F-H-K", "A-B-F-G-H-K-L", "C-H" ); #~ my @idx = findem( "A-E-H-L", \@options ); my @idx = findem( "A-E-H-L", @options ); dd \@options; dd \@idx; dd [ @options[@idx] ]; exit 0; sub findem { #~ my( $query, $options ) = @_; my $query = shift; $query = join '.+', map { "\Q$_\E" } split '-', $query; #~ return indexes { /$query/ } @$options; return indexes { /$query/ } @_; } __END__ [ "A-B-F-G-H-K-M", "A-E-G-H-L", "A-C-E-G-H-J-L", "B-F-H-K", "A-B-F-G-H-K-L", "C-H", ] [1, 2] ["A-E-G-H-L", "A-C-E-G-H-J-L"]
In reply to Re: Pattern Matching with a Selected Sub-String
by Anonymous Monk
in thread Pattern Matching with a Selected Sub-String
by ozboomer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |