balajinagaraju has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am using the Image::Compare module to compare two images and here is my code

sub CompareImage{ print " CompareImage function called"; my @args = @{$_[0]}; print "Arguments:".@args[0]; print "Arguments:".@args[1]; my($cmp) = Image::Compare->new(); $cmp->set_image1( img => '@args[0]', ); $cmp->set_image2( img => '@args[1]', ); $cmp->set_method( method => &Image::Compare::THRESHOLD, args => 25, ); if ($cmp->compare()) { print 'The images are the same, within the threshold'; return 'PASS'; } else { print 'The images differ beyond the threshold'; return 'FAIL'; } }

I am triggering this function from a different file and i am passing an array reference which holds the images to be compared(absolute path to the image files). I am accessing the images using the indexes and itseems to be failing during the comparison, when i print the content of the array i am getting the correct values but if i use it a comparison it fails, however if i hardcode the path values the function works fine. I am getting the below error with the above usage.

CompareImage function called Arguments:D:\\img1.jpg Arguments:D:\\img2.jpg Unable to read image data from file '$args[0]': 'Could not open $args[0]: No such file or directory' at C:/strawberry/perl/site/lib/Image/Compare.pm line 162. Can anyone help me resolve the issue.

Replies are listed 'Best First'.
Re: Problem with Image::Compare module.
by Anonymous Monk on May 03, 2012 at 08:18 UTC

    Its because single quotes do not interpolate while double quotes do interpolate. perlintro and Modern Perl explain interpolation.

Re: Problem with Image::Compare module.
by Anonymous Monk on May 03, 2012 at 08:28 UTC
    Do not use any quotes at all for single variables. Write:
    img => $args[0],
      Thanks for your reply , it works fine now.