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;

In reply to Tk Listbox problem by Sisk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.