views:

205

answers:

2

I installed the following component by MacPorts:

p5-image-info @1.16 (perl, graphics)
Extract meta information from image files

It says in its website that you can use it by

   Usage is something like this:

   use Image::Info qw(image_info);

   @info = image_info("filename");
   $refto_hash_describing_1st_image = $info[0];
   $refto_hash_describing_2nd_image = $info[1];

However, I run unsuccessfully

$perl  use Image::Info qw(image_info);
-bash: syntax error near unexpected token `('
$

How can you get the metadata of an image by the Perl module?

+5  A: 

The syntax described is how you would use it within a Perl script, not how you can use it as a single line from the shell.

Put this in a .pl file (e.g. "image_info.pl"):

#!/usr/bin/perl -w
use strict;
use Image::Info qw[image_info];
use Data::Dumper;

while (@ARGV) {
  print Dumper(image_info(shift));
}

And run it thus:

$ ./image_info.pl file.jpg

and revel in the masses of information it will tell you...

Alnitak
I get the following error message http://dpaste.com/37750/. I have 744 permissions for the script.
Masi
that error means it can't find the Image::Info module in your Perl5 search path.
Alnitak
The problem is apparently in MacPorts. I assumed that MacPorts can put the module to PERL5LIB, which is my only Perl PATH. It obviouly does not do that. Do you need to put the module to your PERL5LIB?
Masi
Masi, change /usr/bin/perl to /opt/local/bin/perl to use the Perl installation you installed with MacPorts.
Ask Bjørn Hansen
@Bjorn: I get the same error message. I tried both perl PATHs in my PATH. I did not have /usr/bin/perl in my PATH initially.
Masi
I have the following now in my .bashrc: export PATH='$PATH:/opt/local/bin:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/bin/perl:'
Masi
Masi: run this and report the result: find / -name Info.pm -ls
Alnitak
@Alnitak: I get the following: http://dpaste.com/39436/
Masi
ok, so put /opt/local/lib/perl5/vendor_perl/5.8.9 in PERL5LIB
Alnitak
I get the following output: http://dpaste.com/42342/ The problem seems to be in encoding. How can you change it?
Masi
A: 

Read http://perldoc.perl.org/perlrun.html