Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Get certain information from MP3::Tag's autoinfo()

by thmsdrew (Scribe)
on Aug 07, 2012 at 19:03 UTC ( #986059=perlquestion: print w/replies, xml ) Need Help??
thmsdrew has asked for the wisdom of the Perl Monks concerning the following question:

MP3::Tag's autoinfo() works as follows:

($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->aut +oinfo(); # or $info = $mp3->autoinfo();

Is there a way to only return specific values from this method? I only want $album and $artist. As I see it, I have to use

($title, $track, $artist, $album) = $mp3->autoinfo();,

which defines $title and $track unnecessarily. Can I accomplish this? I have a feeling it might have something to do with using a hash reference. Not too sure though.

Replies are listed 'Best First'.
Re: Get certain information from MP3::Tag's autoinfo()
by Kenosis (Priest) on Aug 07, 2012 at 20:37 UTC

    Here's another option:

    my ( $artist, $album ) = ( $mp3->autoinfo )[ 2, 3 ];

      Thanks, I rather like this solution!

        You're most welcome, thmsdrew! Glad it worked for you...

Re: Get certain information from MP3::Tag's autoinfo()
by toolic (Bishop) on Aug 07, 2012 at 19:19 UTC
    From MP3::Tag POD:
    autoinfo() returns an array with the information or a hashref. The hash has four keys 'title', 'track', 'artist' and 'album' where the information is stored. If comment, year or genre are found, the hash will have keys 'comment' and/or 'year' and/or 'genre' too.

    Try:

    my $info = $mp3->autoinfo(); # hashref print $info->{album}; print $info->{artist};

    See also:

      So that uses less unnecessary space than my initial way of doing it? Because I'm referencing the hash and not actually declaring all of the variables that I don't need?

        You could do this:

        (undef, undef, $artist, $album) = $mp3->autoinfo();

        But I like toolic's solution better.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://986059]
Approved by toolic
help
Chatterbox?
[MidLifeXis]: Most likely it is a code that some undocumented system, hidden behind layers of IT, deep in the bowels of the building under the machine room floor, reads that code to keep a presence switch from going off. :-b
[MidLifeXis]: I think I forgot "running on a farm of commodore 64, vic 20s, trs 80s, and apple ]|[e systems"
[GotToBTru]: oh I know what it is .. but it is a number only slightly useful to me and of no possible use to our customer
[MidLifeXis]: Whew - you just saved the free world. <o)
[GotToBTru]: i guess it's a placeholder, the code will only fill it in if there is nothing else to use
[GotToBTru]: but then .. if you have nothing to say, why not say nothing?
[MidLifeXis]: I have a user who has a lot of say on how some of our processes work that abhors significant blanks. Perhaps that is a part of it. A not-so-obvious "this space intentionally left blank" indicator.

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2017-01-20 19:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (176 votes). Check out past polls.