On Thursday 23 March 2006 15:51, Christopher Spears wrote:
[ exits after one round ]  but . .
> I want the program to keep asking the user for a
> pattern until an empty string is entered.

One way to do it:  look for: <- added this --
there are 4 of them (4 newly added lines)
wrapped the whole thing in infinite loop
uses last to exit loop (unless something was struck besides just the enter 
key).

#!/usr/bin/perl -w
use strict;

while (1) { # infinite loop  <-added this line ---------------
print "<ENTER> to exit OR\n"; # <- added this ------------
print "Enter a regular expression: ";
chomp(my $pattern = <STDIN>);

last unless $pattern; # the way out  <- added this -------

my $some_dir = "./ex2";
opendir(DIR, $some_dir) || die "Cant open $some_dir: $!";
my @filenames = readdir(DIR);

foreach (@filenames) {
        if (eval {$_ =~ /$pattern/} ) {
           print $_ . "\n";
        }
        print "Continuing after error: $@" if $@;
}
} # end of while(1) <- added this line ---------------------

-- 
Alan C.

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


Reply via email to