I'm not sure what you want to see, so below is the code for the whole subroutine I'm writing

The whole reason I have this subroutine is for user to select some items in the @newSeqUnique array and return the selected array to the calling function

Currently the code is stuck at the MainLoop; statement

sub getSelectedSeq { my $newSeqUniqueRef = shift; my $grp = shift; my @newSeqUnique = @$newSeqUniqueRef; my @newSeqUniqueSorted = sort{$a->{ID} cmp $b->{ID} || $a->{folder} cmp $b->{folder}} @newSeqUnique; my @displayedArr; my $displayedStr; my @selectedArr; foreach (@newSeqUniqueSorted) { $displayedStr = $_->{ID}." - ".$_->{folder}; push (@displayedArr, $displayedStr); } select STDOUT; foreach (@displayedArr) { print "$_\n"; } # my $mw = MainWindow->new(-title=>"Select sequences"); my $mw = new MainWindow; $mw->Label(-text => "Below is a list of sequences not found in exi +sting group $grp table")->pack(); $mw->Label(-text => "Please select sequences to be added to new ta +ble")->pack(); my $lb = $mw->Scrolled("Listbox", -scrollbars => "osoe", -height =>10, -width => 30, -selectmode => "extended"); my $real_lb = $lb->Subwidget('scrolled'); $real_lb->configure(-borderwidth=>2); $lb->insert("end", @displayedArr); $lb->pack(-fill=>"both"); $mw->Button(-text => "Select", -command => sub{@selectedArr=$lb->curselection;$m +w->destroy();})->pack(); $lb->selectionSet('end'); $lb->see('end'); MainLoop(); foreach (@selectedArr) { print "$_\n"; } my @arr; my @temp; my ($index, $ID, $folder, $obj); if ((@selectedArr)&&(defined $selectedArr[0])) { foreach (@selectedArr) { push (@arr, $newSeqUniqueSorted[$_]); } }else { @arr = (); } return \@arr; }

In reply to Re^2: Perl Tk unable to return from MainLoop when implemented in a subroutine by ngocanh
in thread Perl Tk unable to return from MainLoop when implemented in a subroutine by ngocanh

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.