Using the proper comparison operator makes a great difference, you're comparing strings hence your operator to use is "eq", if you were comparing numbers however, you would have used "==" instead, this said, you know by now that "=" is the assignment operator.

using:

use strict; use warnings;
at the top of each program saves you a lot of trouble, notice, when the strictures are on you would have to declare your variables using "my" the first time the variable is brought to existence, this has got to do with proper scoping and serves also to save you headaches from typing errors in variable names

Now here is how your program would look like after corrections. Notice I did not use escaping by \n to put an apostrophe in you're because it is (i.e ' ) not one of Perl's metacharacters.

#!/usr/local/bin/perl use strict; use warnings; print "What is your name?\n"; chomp(my $name = <STDIN>); if ($name eq 'larry') { print "You're Larry!\n" } elsif ($name eq 'moe') { print "You're Moe!\n" } elsif ($name eq 'curly') { print "You're Curly!\n" }
Just like GrandFather said, using a data structure like hashes is the answer to avoid repetitive code-writing. Another thing, Perl boasts of a capability called TIM TOWDY which means "There is more than one way to do it", and here is another way to do your program in addition, using another type of data structures called arrays to hold the names for you and the rest of the code just checks the condition when the name exists and prints it:
#!/usr/local/bin/perl use strict; use warnings; my @names =qw(larry moe curly); print "What is your name\n"; chomp(my $name = <STDIN>); if(grep {/$name/} @names){ print "you're @{[grep {/$name/} @names]}!\n"; }else{ print "I don't know this name\n"; }
Update: Hashes are more flexible to work with as GrandFather duly explained. I wish you a happy Perl programming, it is just real fun to learn Perl.

Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

In reply to Re: elsif failing by biohisham
in thread elsif failing by rcd^_-

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.