[Za-pm] getting out of <STDIN> loop

James E Keenan jkeen at verizon.net
Sun Aug 9 07:07:00 PDT 2009


On Aug 9, 2009, at 8:39 AM, Anne Wainwright wrote:

> (Am in fact referring to Exercise 2 Chapter 2 of
> Schwartz et al INTERMEDIATE PERL.)
>
> First, while realising that the official solution is a masterpiece of
> condensed perl code, I don't understand why the first
> line has the (1) ).
>
> -----------------------------------------------------------
> while(1) {
>     print "Enter a regular expression to match filenames> ";
>     chomp(my $regex = <STDIN>);
>     last unless (defined $regex && length $regex);
>     print map {"    $_\n"} grep {eval{/$regex/}} glob(".* *");
> }
> -----------------------------------------------------------
>

I don't have my copy of Intermediate Perl handy, but, in general,  
with an infinite loop such as that cited above the expectation is  
that at some point you will either compose a pattern that matches the  
filename and then automatically exit via 'last', or you will give up  
in frustration by hitting Ctrl-C (in *nix).


More information about the Za-pm mailing list