in reply to How can I find the occurrence of a variable in each line of an array

Well it's not clear if you want multiple matches to be listed separately, like "lacy smith" twice.

If not I'd just construct an "or"ed regex with all search terms.

DB<127> @search=qw/smith sanders/ => ("smith", "sanders") DB<128> $regex= join "|", @search => "smith|sanders" DB<129> @matches = grep { /($regex)/ } @full => ( "Bob-smith#anthropology", "Sandy-smith#sociology", "Tom-sanders#english", "Anthony-sanders#english", ) DB<130> @full => ( "Bob-smith#anthropology", "Sandy-smith#sociology", "Tom-sanders#english", "Tina-lacy#socialwork", "Anthony-sanders#english", )

update

improved code

BTW we appreciate if you post real code not just multiply broken pseudo stuff. :)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

  • Comment on Re: How can I find the occurrence of a variable in each line of an array
  • Download Code