A Diumenge 22 Octubre 2006 18:38, Gav Ford va escriure: > Hello, > > I'm just starting out here and hope someone can help, I think I've > gotten all confused over how to read values from a Hash. > > Or it could be I've just got totally the wrong end of the stick. > > The data in question is the album art attached to an MP3 file. I'm > trying to read it from the MP3 and save it as a file. I'm using a > module I got from cpan called MP3::Tag. > > Here is my program so far, see if this makes things clearer. > > > > #!/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(); > > $art = $artinfo{"_Data"}; # or it could fault > > > # write the art to file > open ARTWORK, ">$album.jpg" or die "File $album.jpg could not be > opened.\n"; print ARTWORK $art; > close ARTWORK; > > > > Things seem fine, It can read the artist, album and track names and all > this goes well. The documentation tells me that get->frame() will > return simple strings I can use and this is so. > > For PIC it should return a Hash containing keys called 'Image Format', > 'Picture Type', '_Data', 'Description' and 'encoding' and a string > > The data I want is attached to the key '_Data'. > > However it seems to return two strings 'HASH(0x8356294)' and 'Attached > picture' when I read it to an array or a set of comma separated scalars. > > I feel that the value HASH(0x8356294) is somehow a clue, but I can't > figure out how to access what I want from it. > > Please could somebody point me in the right direction? > > -Gav 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.
cheers, -- Xavier Mas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>