Pooja Dubey
Pooja Dubey

Reputation: 683

Grep Values from a String in perl

I have array that will have some values like this :

("test","test1","test3").

Now i have a string that will have values like this "test","test4","test3","test5"

I want to get the matching values from string that are in the array

@has = grep(m/$_/i,$strin) @array_list;

How can we do this please help me in this.

Upvotes: 1

Views: 172

Answers (1)

rubikonx9
rubikonx9

Reputation: 1413

What you want is this:

@has = grep { $string =~ m/$_/ } @array_list;

In general, this code block should return true for the elements, which you want to have grepped.

Upvotes: 2

Related Questions