Hmm. I thought it might be something like that, but now instead of a nebulous feeling that it must be something to do with returning values I actually know how it works! Very educational - thanks for the explanation. My subroutines will be grateful too.

So (just getting this straight, hoping my thought processes won't be too dull for others) in jerrygarciuh's case, if he replaces the if... else with
print "$in was not a number!"; input() unless $in =~ /\d/;
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 like
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/; }
Would that work? Is it nicer? Have I learnt something from this exchange? (The answer to at least one of these questions is "yes".)

§ George Sherston

In reply to Re: Re: Re: Can this If/Else be condensed into a 1 liner with a trailing If? by George_Sherston
in thread Can this If/Else be condensed into a 1 liner with a trailing If? by jerrygarciuh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.