I have an array with original data and a column in excel file, I need to compare the excel column with the array and find the match.
I need is walk should match with walk with me and so on, Is there any way I can do it.
can i compare individual string with complete array i am comparing excel row with array using the following way description variable contains string to match with @steps_name array
my @steps_name=("1-2 Steps", "5-7 Steps", "8-10 Steps", "11-15 Steps");
foreach $sheet (@{$workbook->{Worksheet}}) {
foreach $col ($sheet->{MinCol} .. $sheet->{MaxCol})
{
if ($sheet->{Cells}[0][$col]->{Val} eq "DESCRIPTION")
{
$description = $col;
}
}
foreach $row ($sheet->{MinRow}+1 .. 50)
{
my $db_description = $sheet->{Cells}[$row][$description]->{Val};
my $needle_regex = quotemeta $db_description;
if (grep { /(?i)\Q$db_description\E/ } @steps_name)
{
print "<br><h1>Element '$db_description' found </h1></br>" ;
}
else
{
print "<br>$db_description not found </br>"
}
}
}
Thanks in advance.
Assigning a list to a scalar (
$db_description
) doesn't make any sense. Also,eq
tests for string equality, and none of the strings you're comparing will ever be equal. You probably want to use a regular expression to see if your needles match part of your haystacks:This could be shortened to: