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

Dear Monks,
I have a piece of code that is just not compiling:

I want to be able to display a set of options in a dropdown menu and want to call a subroutine whenever the user selects an option from it.

here is how my current code looks like:
@vars = ("a1", "b2", "c3"); $opt = $w1->Optionmenu(-options=>\@vars, -variable=>\$tvars -command=> sub { print "got : ", shift, "\n"})->pac +k;
I get a compilation error as follows:
Tk::Error: Odd number of args to Tk::Optionmenu->new(...)
anyone had any experience similar to this?
Thanks in advance for your help!

Replies are listed 'Best First'.
Re: Error with perl tk::OptionMenu
by shmem (Chancellor) on Sep 03, 2008 at 21:53 UTC
    @vars = ("a1", "b2", "c3"); $opt = $w1->Optionmenu(-options=>\@vars, -variable=>\$tvars -command=> sub { print "got : ", shift, "\n"})->pac +k; # ----------------^ # missing comma.
      Thanks a bunch, shmem.! cant believe i tried so many variations of this and missed out on the comma. appreciate ur help! Thanks again!