Greatings monks.
Here's my problem. I'm trying to write a launcher for my NES, SNES, and Genesis emulators but my code isn't working right. When I try to run it, I get 'Can't call method "delete" on an undefined value'. The line number it points at is the first line of the changeList subroutine. Anyway, here's the code. Can anyone tell me what's wrong with it?
#!/usr/bin/perl
use Tk;
use Switch;
# Variables for emulators
$snesCommand="zsnes";
$genesisCommand="dgen";
$nesCommand="nestra";
$snesDirectory="~/roms/nes/";
$genesisDirectory="~/roms/genesis/Roms/";
$snesDirectory="~/roms/snes/Roms/";
$mw=MainWindow->new(-title=>"Launcher");
#Main window elements
$systemPick=$mw->Optionmenu(-command=>\&changeList,
-variable=>\$system);
$systemPick->addOptions("SNES","NES","Genesis");
$opt=$mw->Scrolled("Listbox",-selectmode=>'single',
-scrollbars=>"se");
$go=$mw->Button(-text=>"Launch Game",
-command=>\&gogo);
# Geometry
$systemPick->pack();
$opt->pack(-expand=>1,-fill=>"both");
$go->pack();
sub changeList {
$opt->delete(0,'end');
switch ($system) {
case "SNES" {
$command=$snesCommand;
$directory=$snesDirectory;
@dir=glob($snesDirecotry);
foreach my $file(@dir) {
$file=~s/$directory//;
$opt->insert('end',$file);
}
}
case "NES" {
$command=$nesCommand;
$directory=$nesDirectory;
@dir=glob($nesDirecotry);
foreach my $file(@dir) {
$file=~s/$directory//;
$opt->insert('end',$file);
}
}
case "Genesis" {
$command=$genesisCommand;
$directory=$genesisDirectory;
@dir=glob($genesisDirecotry);
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;