store result of serch using grep in perl

by kalai 2008-12-01 20:32:15

If you want to search presence of particular value in an array, you can make use of grep command to search the value.
If the searched value is present, it can be stored as an array by assigning grep command result to an array variable.
when u print array, you will get the searched value.

if((@tk=grep {$_ =~ /search string /} @array)
{
foreach $ts (@tk){
$str=$str.$ts;
}
print $str;
}

By using this single command you can check where particular string or value is present in the array or not instead of looping
through the array.

Tagged in:

1397
like
0
dislike
0
mail
flag

You must LOGIN to add comments