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

Hi, i was wondering if its possible to run a while, while doing something else. The problem is i am reading a non stop stream and i am using win32::GUI. While reading the stream, its unpossible to use the frontend to exit or whatever? Thanks

Replies are listed 'Best First'.
Re: Do While, While
by bart (Canon) on Apr 07, 2008 at 17:49 UTC
Re: Do While, While
by BrowserUk (Patriarch) on Apr 07, 2008 at 17:49 UTC
      I keep on reading the stream. I´m saving information of coming commands.
      # Keep reading lines from the server. while (my $input = <$server>) { #save incoming information to database ... do this and that # Check errormessages and .... }
      But I would still like to use the frontend

        This ain't gonna do what you need to do, but given the sparsity of information supplied...

        use threads; ... async{ # Keep reading lines from the server. while (my $input = <$server>) { #save incoming information to database ... do this and that # Check errormessages and .... } };

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
      thanks i´ll try

        Try this. It's a starting point.

        #! perl -slw use strict; use threads; use Win32::GUI; my $mw = Win32::GUI::Window->new( -name => 'Main', -width => 500, -height => 500, ); my $lb = $mw->AddListbox( -name => 'LB' ); $lb->Add( 'Line ' . $_ ) for 1 .. 10; $mw->Show(); my $thread = async{ my $lb = shift; $SIG{'KILL'} = sub { return 0; }; my $n = 11; while( sleep 1 ) { $lb->Add( 'Line ' . $n++ ); } } $lb; $thread->detach; Win32::GUI::Dialog(); exit(0); sub Main_Terminate { $thread->kill( 'KILL' ); return -1; } sub Main_Resize { $lb->Width( $mw->Width ); $lb->Height( $mw->Height ); } sub LB_Click { print 'click'; } sub LB_MouseRightDown { print 'Rclick'; }

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.