Hello :),
Consider the following code.
my @sugs; @sugs=&suggestcomb($gotfile); #print "@sugs\n"; my $top = new MainWindow; my $lsugs=@sugs; #print"\nThe length of the array:"; #print "\n$lsugs"; $opt1="$sugs[0]"; $opt1='Nil' if !$opt1; #print "\n$opt1"; $opt2="$sugs[1]"; $opt2='Nil' if !$opt2; #print "\n$opt2"; $opt3="$sugs[2]"; $opt3='Nil' if !$opt3; #print "\n$opt3"; $opt4="$sugs[3]"; $opt4='Nil' if !$opt4; #print "\n$opt4"; my $l = $top->Label(-text => "Press right button\nfor popup menu.")->p +ack; my $m = $top->Menu(-tearoff => 0,font => "{arial} 12 {bold}",-menuitem +s => [ [Button => "$opt1", -command => \&replace1], [Button => "$opt2", -command => \&replace2], [Button => "$opt3", -command => \&replace3], [Button => "$opt4", -command => \&replace4], ] ); $top->bind("<Button-3>" => sub { $m->Popup(-popover => "cursor",popanc +hor => 'nw') }); } 1;
The number of strings returned by &suggestcomb and stored in @sugs may be different each time the subroutine is called.

I need to change the code so that we consider only the first four elements in @sugs, and so that there are as
many buttons in the pop-up menu as there are strings in @sugs.
For e.g if there are only two strings
in @sugs, we should have only two buttons, instead of four buttons, with the last two having the label "Nil" on them.

The max. no of buttons can be four,and the min. one.In case there are no elements in @sugs a single button should
display something like "None".

Right now the number of buttons is hard-coded to four.
Thanks in advance for any help.:)

In reply to Tk Menu question. by perl_seeker

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.