Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Hash references and Exif data

by Anonymous Monk
on Sep 06, 2007 at 22:37 UTC ( [id://637552]=perlquestion: print w/replies, xml ) Need Help??

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

Two questions.

I'm making an image gallery and am using Image::EXIF to extract the exif data. It produces a hash reference and up til now (years and years after using Perl) I've never in my life had to use a hash reference. I don't know how to break it into usable data. Can someone show me how I'd take %image_info (hash reference) and get data from it?

As far as EXIF, does this information disappear from an image if it's edited with PhotoShop, PaintShopPro, etc? Or is it semi-permanently attached to images?

Replies are listed 'Best First'.
Re: Hash references and Exif data
by Minimiscience (Beadle) on Sep 06, 2007 at 23:33 UTC
    %image_info isn't the hash reference; $image_info is. References are stored as scalars, and in order to dereference them, you have to use special syntax. To treat the reference as a normal hash, write it as %$image_info, and to access just a single element from it, write $image_info->{key}.

    I don't know anything about EXIF, though.

Re: Hash references and Exif data
by ikegami (Patriarch) on Sep 07, 2007 at 06:00 UTC

    Where you'd use %image_info when using a hash, use %$image_info instead.
    Where you'd use $image_info{$key} when using a hash, use $image_info->{$key} instead.
    It's that simple.

    See Dereferencing Syntax
    and References Quick Reference

Re: Hash references and Exif data
by sulfericacid (Deacon) on Sep 06, 2007 at 22:48 UTC
    Can't help with the EXIF data but I suppose once it's in a format outside its original, it loses the fingerprints.

    For the hash reference, you have to create a k/v pair for each key inside of your referenced hash. Dirty.

    while( my ($k, $v) = each %$image_info ) { print "key: $k, value: $v.\n"; }


    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid
Re: Hash references and Exif data
by Gangabass (Vicar) on Sep 07, 2007 at 05:37 UTC

    Try something like this:

    my $image_info = $exif->get_image_info(); foreach my $key ( keys %{$image_info} ) { print $key, " => ", $image_info->{$key}, "\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://637552]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found