in reply to Tk Listbox problem

1) you're using Switch module (the author himself says you shouldn't use it).
2) you're not using strict/warnings
3) you're not using <code></code> tags

Replies are listed 'Best First'.
Re^2: Tk Listbox problem
by Sisk (Novice) on Feb 19, 2009 at 06:04 UTC
    Ok, I rewrote it using strict and warnings and replaced the switch with if/elsif statements. I have $opt declared as a global, but it's throwing the exact same error it was before For some reason I had a brain fart and forgot to use the <code> tags. Sorry about that. It's fixed now.
    #!/usr/bin/perl use Tk; use warnings; use strict; # Variables for emulators use vars qw($snesCommand $genesisCommand $nesCommand $snesDirectory $n +esDirectory $genesisDirectory $opt $system $directory $command); $snesCommand="zsnes"; $genesisCommand="dgen"; $nesCommand="nestra"; $snesDirectory="~/roms/nes/"; $genesisDirectory="~/roms/genesis/Roms/"; $snesDirectory="~/roms/snes/Roms/"; my $mw=MainWindow->new(-title=>"Launcher"); my $systemPick=$mw->Optionmenu(-command=>\&changeList, -variable=>\$system); $systemPick->addOptions("SNES","NES","Genesis"); $opt=$mw->Scrolled("Listbox",-selectmode=>'single', -scrollbars=>"se"); my $go=$mw->Button(-text=>"Go for it", -command=>\&gogo); # Geometry $systemPick->pack(); $opt->pack(-expand=>1,-fill=>"both"); $go->pack(); sub changeList { $opt->delete(0,'end'); if ($system=="SNES") { $command=$snesCommand; $directory=$snesDirectory; my @dir=glob($snesDirectory); foreach my $file(@dir) { $file=~s/$directory//; $opt->insert('end',$file); } } elsif ($system=="NES") { $command=$nesCommand; $directory=$nesDirectory; my @dir=glob($nesDirectory); foreach my $file(@dir) { $file=~s/$directory//; $opt->insert('end',$file); } } elsif ($system=="Genesis") { $command=$genesisCommand; $directory=$genesisDirectory; my @dir=glob($genesisDirectory); foreach my $file(@dir) { $file=~s/$directory//; $opt->insert('end',$file); } } } sub gogo { my $selected=$opt->get($opt->curselection()); system("$command $directory$selected"); } &changeList; MainLoop;