Notices
Results 1 to 4 of 4

Thread: Really simple yet annoying problem!! -_-

  1. #1 Really simple yet annoying problem!! -_- 
    Forum Freshman
    Join Date
    Oct 2010
    Location
    Aberystwyth University
    Posts
    10
    Hey guys, I am very new to programming and I am in my first month of learning it at Uni,

    I currently have this code that i'm working on to keep sharp, in my other programs it works fine but ever since I thought it had become second nature it doesn't produce the results I want.

    Here is the code:

    print "Shwmae!\n";
    print "Welsh or English?!\n";
    $answer = <STDIN>;

    if ($answer eq "Welsh")
    {

    print "Diolch!!\n"
    }

    else
    {
    print "Thank You!!\n"
    }

    I am using PERL (btw).

    Basically what happens is if I type in Welsh (<STDIN>) it will still produce "Thank You!!" as a result and clearly I am looking for the welsh translation.

    What is going on guys?! this is really simple... haha

    Cheers,
    CGK30


    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Professor
    Join Date
    Jul 2008
    Location
    New York State
    Posts
    1,267
    Wild guess: When you type in "Welsh", the computer doesn't match it exactly to "Welsh" in the program. Maybe an extra (blank) character.


    Reply With Quote  
     

  4. #3  
    Forum Isotope (In)Sanity's Avatar
    Join Date
    Oct 2004
    Location
    Mesa AZ
    Posts
    2,699
    Try using == instead of eq.
    Pleased to meet you. Hope you guess my name
    Reply With Quote  
     

  5. #4  
    Forum Isotope (In)Sanity's Avatar
    Join Date
    Oct 2004
    Location
    Mesa AZ
    Posts
    2,699
    or....perhaps it's adding a cr and/or lf at the end of the input. == is for numeric comparisons, so I get that one wrong. Too many languages in my head.
    Pleased to meet you. Hope you guess my name
    Reply With Quote  
     

Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •