in reply to Can this If/Else be condensed into a 1 liner with a trailing If?
which does get it on one line, though not, I agree, with a trailing if :). On the other hand if the lineprint "$in was not a number!"; input() unless $in =~ /\d/;
is a line you need (perhaps an idiom I don't know - if so, what does it do? - in any event it has a certain classically simplicity about it) - then to get it on one line you could use the conditional operator, although there might be some pros and cons here I don't know about:$in;
That doesn't let you call input(), but that's ok if you agree with lesstrat that it might get a bit ropey if you call input() from within input().$in =~ /\d/ ? $in : print "$in was not a number!";
But this question is much more complicated than one would think, as these and threads explain.$in !~ /\D/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Can this If/Else be condensed into a 1 liner with a trailing If?
by suaveant (Parson) on Oct 02, 2001 at 18:07 UTC | |
by George_Sherston (Vicar) on Oct 03, 2001 at 10:25 UTC | |
by suaveant (Parson) on Oct 03, 2001 at 18:17 UTC | |
|
Re: Re: Can this If/Else be condensed into a 1 liner with a trailing If?
by {NULE} (Hermit) on Oct 02, 2001 at 20:25 UTC |