bazz
02-17-2010, 05:43 PM
Hi,
I am looping through an array and trying to grep to see if each variable, is on another array.
while (my ($images, $text )=$sth->fetchrow_array) {
$images_hash{$images}=$text;
push (@images_in_db,$images);
}
print Dumper \%images_hash; #ok
print qq( aidb=@images_in_db <br />); #ok
print qq( imgs=@images <br /> ); #ok
foreach my $image (sort @images){
if (grep $image, \@images_in_db ){
print qq( image match $image <br /> );
} else {
print qq( no image match <br /> );
}
}
Currently shows all to be a match when clearly they are not. :(
@images_in_db=image06.jpg image07.jpg image08.jpg
@images=image01.jpg image02.jpg image03.jpg image04.jpg image05.jpg image06.jpg image07.jpg image08.jpg
Can anyone see what I am overlooking please? Maybe I should grep in the while loop before building the second array, @images_in_db?
bazz
I am looping through an array and trying to grep to see if each variable, is on another array.
while (my ($images, $text )=$sth->fetchrow_array) {
$images_hash{$images}=$text;
push (@images_in_db,$images);
}
print Dumper \%images_hash; #ok
print qq( aidb=@images_in_db <br />); #ok
print qq( imgs=@images <br /> ); #ok
foreach my $image (sort @images){
if (grep $image, \@images_in_db ){
print qq( image match $image <br /> );
} else {
print qq( no image match <br /> );
}
}
Currently shows all to be a match when clearly they are not. :(
@images_in_db=image06.jpg image07.jpg image08.jpg
@images=image01.jpg image02.jpg image03.jpg image04.jpg image05.jpg image06.jpg image07.jpg image08.jpg
Can anyone see what I am overlooking please? Maybe I should grep in the while loop before building the second array, @images_in_db?
bazz