"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

How about:

        1 until <> =~ /^\s*([yn]?)\s*$/i;
        $choice = uc$1 || 'Y';

-- 
Rick Klement

Reply via email to