Michael Alipio wrote:
> 
> I have a sub that returns a value and inside it runs a loop that displays 
> something on the screen, say a list of numbered items. Now what I want to do
> is if the item i'm interested appears on the screen, the user can hit any key
> and the program will exit the sub and return what ever it is supposed to
> return.
> 
> Any idea how to accomplish that?

I'm not clear if the "what ever it is supposed to return" is related to the key
press or not. If not then perhaps the subroutine should be broken into two.

Anyway, it sounds like what you want to do is to break out of a loop when a key
is pressed. The program below prints dots until a key is pressed and then says
how many have been printed. Does that help?

Rob


use strict;
use warnings;

use Term::ReadKey;

my $n = 0;

while () {
  print '.';
  last if ReadKey(-1);
  $n++;
}

print $n;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to