in reply to Re: Re: Can this If/Else be condensed into a 1 liner with a trailing If?
in thread Can this If/Else be condensed into a 1 liner with a trailing If?
then the subroutine will return the number of characters chomped from $in, rather than $in itself. So in order to reduce the if... else loop to a single line, one wd have to do something likeprint "$in was not a number!"; input() unless $in =~ /\d/;
Would that work? Is it nicer? Have I learnt something from this exchange? (The answer to at least one of these questions is "yes".)sub input { my $arrayref=shift; print "\nSo far you've guessed @$arrayref." if $arrayref; print "\nWhat is your guess?\n"; chomp <STDIN>; my $in=<STDIN>; print "$in wasn't a number!";input() unless $in =~ /\d/; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Can this If/Else be condensed into a 1 liner with a trailing If?
by suaveant (Parson) on Oct 03, 2001 at 18:17 UTC |