A variable named RestrictedNames holds the list of restricted user names. SplitNames is an array variable which holds the complete set of user name. Now I have to check whether current name is found in RestrictedNames variable like using instr.
@SplitNames = ("naag algates","arvind singh","abhay avasti","luv singh","new algates") and now i want to block all the surnames which has "singh" ,"algates" etc.
@SplitNames = ("naag algates","arvind singh","abhay avasti","luv singh","new algates")
$RestrictedNames="tiwary singh algates n2 n3 n4 n5 n6";
for(my $i=0;$i<@SplitNames;$i++)
{
if($RestrictedNames =~ m/^$SplitNames[$i]/ ) //google'd this condition, still fails
{
print "$SplitNames[$i] is a restricted person";
}
}
You should modify this line:
to
^looks for a match from the beginning.For more details about perl metacharacters, see here
EDIT:
If you need blocking based on surnames, try this code in the for-loop body.