Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Tk::Listbox=HASH Error

by shockme (Chaplain)
on Dec 13, 2002 at 20:47 UTC ( #219746=perlquestion: print w/replies, xml ) Need Help??

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

In my ongoing quest to learn Perl::Tk, I've stumbled upon an error that has me stumped. First, the code:
use MP3::Info; ... sub getInfo { # entry is a single line from the .m3u # which is the path up to and including the # song file. my ($entry) = shift; if ($entry =~ /\.ogg$/i) { my $ogg = Ogg::Vorbis->new; open(IN, "< $entry"); $ogg->open(IN); my $oggInfo = $ogg->info; my %tag = %{$ogg->comment}; close(IN); foreach my $key (keys %tag) { if ($key =~ /^artist/) { $info{artist} = $tag{$key}; } elsif ($key =~ /^album/) { $info{album} = $tag{$key}; } elsif ($key =~ /^title/) { $info{song} = $tag{$key}; } elsif ($key =~ /^genre/) { $info{type} = $tag{$key}; } elsif ($key =~ /^date/) { $info{year} = $tag{$key}; } } } elsif ($entry =~ /\.mp3$/i) { my $mp3hashref = get_mp3tag ($entry); my %mp3tag = %$mp3hashref if ($mp3hashref); $info{artist} = $mp3tag{ARTIST}; $info{album} = $mp3tag{ALBUM}; $info{song} = $mp3tag{TITLE}; $info{type} = $mp3tag{GENRE}; $info{year} = $mp3tag{YEAR}; } }

The above subroutine basically extracts either MP3 or Ogg tags from song files and populates the $info hash (which in turn populates the UI.

For the most part, it works flawlessly. However, every so often it crashes with the following:

Tk::Error: Tk::Listbox=HASH(0x8646f6c) is not a Tk object at /usr/lib/ +perl5/site_perl/5.8.0/i386-linux-thread-multi/ line 91. (command + bound to event)

The really odd part (to my mind) is that if I comment out the line

my %mp3tag = %$mp3hashref if ($mp3hashref);

the script runs just fine. Of course, the UI is never populated with anything, but it doesn't crash either.

If anyone has any suggestions, I'd really appreciate it. (The entire script is way too long to post here. If you want to view the entire script, the CVS is available at or contact me and I'll be glad to email it to you.


If things get any worse, I'll have to ask you to stop helping me.

Replies are listed 'Best First'.
Re: Tk::Listbox=HASH Error
by tedrek (Pilgrim) on Dec 14, 2002 at 00:20 UTC
    First off, is this the *only* error you get? or do you also get some error about this line?
    my %mp3tag = %$mp3hashref if ($mp3hashref);
    if so the solution is to fix whatever is wrong on that line. If not, I'm rather at a loss for how to fix it...

    As for what is giving you that Tk::Error message, it appears that someplace in &loadAlbum a run time error is being generated, a die or something. The way Tk appears to handle this without completely crashing is to eval any subroutine calls from a handler, which normally works great, however in your case the Listbox gets destroyed before the error is generated so when Tk goes to handle the error it tries to use whatever is the current widget (in this case the Listbox) and throws another error when it finds that widget has already been destroyed which is the error you posted.

    Hope that's clear enough.
(shockme) Re: Tk::Listbox=HASH Error
by shockme (Chaplain) on Dec 14, 2002 at 01:37 UTC
    dree wrote (in a private message):
    Hello! Not $info{artist} = $mp3tag{ARTIST}; but $info{artist} = $mp3hashref->{ARTIST}; and delete my %mp3tag = %$mp3hashref if ($mp3hashref);

    *sigh* Man, these late nights are gonna kill me. Or make me stupider. Thanks dree. That did the trick!

    If things get any worse, I'll have to ask you to stop helping me.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://219746]
Approved by vagnerr
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2020-10-01 02:24 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (172 votes). Check out past polls.