1 while $_ = <>, !m[^\s*(y|n|)\s*$]i;
$choice = uc $1 || 'Y';

The major discrepancy is that if <> runs dry, you get a warning, and
$choice ends up as 'Y' instead of undef.  Should that situation be handled
cleanly?

LP^>

On Thu, Sep 05, 2002 at 01:37:05PM -0400, Selector, Lev Y wrote:
> Hello,
> 
> What would be a more elegant (short) way to express the following:
> 
> while ($choice = uc <>) {
>   $choice =~ s/(^\s+|\s+$)//g;
>   $choice = 'Y', last if ($choice =~ /^Y?$/);
>   $choice = 'N', last if ($choice =~ /^N$/ );
> }
> 
> As you see, it is an infinite loop which wouldn't let you out unless you do:
> 
> 'y','Y',<ENTER>  - 'Y'
> 'n','N'          - 'N'
> 
>   
> Warmest Regards, 
> Lev Selector

Reply via email to