1

i need to automatically update an optionmenu in Perl Tk by tying an array to an Optionmenu if possible.

To give an example, i can do this successfully with a listbox:

tie @datafile, "Tk::Listbox", $lb;

However, when I try doing the same for an Optionmenu it fails to AUTOLOAD.

tie @optionfile, "Tk::Optionmenu", $om;

Is this not possible? Or am I doing something wrong? Thanks.

Jesse Hernandez
  • 307
  • 2
  • 15

1 Answers1

0

After reviewing the module I noticed a solution, although longer--still a solution. I hope this helps someone out there working with this old stuff.

Here is the module: http://cpansearch.perl.org/src/SREZIC/Tk-804.031/Tk/Optionmenu.pm

Adding an option to the optionmenu

# Add to the array 
push @datafile3, $newReport;
# Add to the optionmenu
$om->addOptions($newReport);

Then the removal

# removing an option from the array and also the optionmenu itself. 
my $index = 0;

# remove from array
$index++ until $datafile3[$index] eq $selectBatch;
splice(@datafile3, $index, 1);
# remove from menu
$om->configure( -options  => [@datafile3]);
Jesse Hernandez
  • 307
  • 2
  • 15