A few things. First, if you want to compare a value against a few others, you just have to repeat it:
$input ne 'good' && $input ne 'bad' && $input ne 'iffy'
Note the use of && instead of ||. If you'd use || the condition would be true if $input was both 'good', 'bad' and 'iffy' at the same time. This can't happen.

However, in your example, you don't need this test at all. You've already covered the cases for 'good', 'bad' and 'iffy', so by the time you get here, you already know $input isn't containing any of them. Write your chain as:

if ($input eq 'good') {print "..."} elsif ($input eq 'bad') {print "..."} elsif ($input eq 'iffy') {print "..."} else {next} last;
Now, if all you do is printing strings in your cases, you could have used a hash, and simple print the appropriate value from the hash, but that draws away into details not related to the control flow questions you have.

Finally, your loop stinks. You have a while loop whose guard is always true, but then inside you read unconditionally from standard input. What if there's nothing more to read?

I would write that as:

print "Are you having/had a good, bad, or iffy day $name?: "; while (my $input = <>) { chomp $input; if ($input eq 'good') {print "..."; last} elsif ($input eq 'bad') {print "..."; last} elsif ($input eq 'iffy') {print "..."; last} print "Are you having/had a good, bad, or iffy day $name?: "; }
Note that I preferred to repeat the 'last' in the various blocks, and that I got rid of the 'next' statement. This code stops processing input if there's no more input - that's what the while is doing.

Purists may object to the duplication of the code - the printing of the prompt happens twice. If so, one could use IO::Prompt or write something like:

while (do {print "...."; defined (my $input = <>)}) { if (...) {...; last} elsif (...) {...; last} elsif (...) {...; last} }
But I prefer the duplication of code over the added complexibility.
Perl --((8:>*

In reply to Re: A better understanding of while () loops by Perl Mouse
in thread A better understanding of while () loops by sub_chick

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.