xavier mas wrote:
to assing values to a (key of ) hash do as: $hash_name{$key_name} =
$value_name. to read same pair key/value use each function into a while loop: while (($key_name, $value_name)) = each %hash_name). sign % indicates the whole hash.

Thanks for the help, I"m sorry if I'm a bit slow. With your help I've got it working now.

So I can't access a value from the hash directly? I have to step though until I hit the key I want?

The other mistake I was making seemed to be I was trying read the Hash as just %artinfo instead of assigning to it as $artinfo and read from it as %$artinfo.

I don't really understand when to use %$ and when to use % or $ to read and write from and to a Hash. Would someone be so kind as to giving me a simple explanation?

 -Gav



Here is the working version of my program:


#!/usr/bin/perl -w

use MP3::Tag;

chomp ($filename = $ARGV[0]);

print "Getting art for $filename \n";

$mp3 = MP3::Tag->new($filename);

$mp3->get_tags();

$tagdata = $mp3->{ID3v2} if exists $mp3->{ID3v2};

$title  = ($tagdata->get_frame("TIT2"));
$artist = ($tagdata->get_frame("TPE1"));
$album  = ($tagdata->get_frame("TALB"));

print "This is $title by $artist\, from the album $album.\n";
print "So I'll call the artwork file: $album\.jpg \n";


$artinfo = $tagdata->get_frame("PIC");  # doesn't seem to work?

$mp3->close();

while (($key, $value) = each (%$artinfo)) {

 if ($key eq "_Data") {

   $art = $value;

 }

}


# write the art to file
open ARTWORK, ">$album.jpg" or die "File $album.jpg could not be opened.\n";
print ARTWORK $art;
close ARTWORK;




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to