My bet is with the first reply -- if the user is entering answers at the keyboard, perl is reading the final "\n" that has to be typed in order to complete each input, and you have to use "chomp" to get rid of that.

As for making progress, you made the task harder for us (and less helpful for you) by showing us disjointed snippets and leaving things out. Next time, see if you can create a short script that can be run by itself and will demonstrate the problem you are having. For instance, your post could have been like this:

Why is it that the script below always prints "huh?", even though I definitely provide the input that should produce a different output?
#!/usr/bin/perl use strict; my @answers = ( 'me', 'you' ); print "Who needs more help, me or you? "; my $response = <STDIN>; if ( $response eq $answers[0] ) { print "Good luck with that.\n"; } elsif ( $response eq $answers[1] ) { print "So help me!\n"; } else { print "huh?\n"; }

Given a situation like that, the vast majority of monks could tell you immediately, with no questions or doubt, that you need to "chomp" the input when reading from STDIN. (Or else they would tell you where to read about that in docs, tutorials, books, etc.)


In reply to Re: Control Structure problem, mistake can't be found by graff
in thread Control Structure problem, mistake can't be found by koolgirl

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.