in reply to I need some beginners help

Since I don't have Learning Perl in front of me, I can't help you with the specifics.

However, I can give you some suggestions regarding asking for help on PerlMonks.

  1. Type in the code. Put it between <code> tags, to keep its formatting.
  2. Tell us what's happening. Again, it's helpful to do so within its own set of <code> tags.
  3. Tell us what version of Perl (most people are either on 5.005 or 5.6.0) and what type of OS (Windows, Unix, Mac, etc). There are some slight differences between the version of Perl and the OS types, which could affect an answer.
Most importantly, welcome aboard! :)

------
/me wants to be the brightest bulb in the chandelier!

Replies are listed 'Best First'.
Re: Re: I need some beginners help
by betsyt (Initiate) on Aug 07, 2001 at 00:36 UTC
    ok here is the code:
    #!usr/bin/perl print "What is your name? "; $name = <STDIN>; CHOP($NAME); IF ($NAME EQ "RANDAL") { PRINT "HELLO, RANDAL! HOW GOOD OF YOU TO BE HERE!\N"; } ELSE { PRINT "HELLO, $NAME!\N"; #ORDINARY GREETING }
    What is hapening is when I go to dos I type in perl hello.pl and it says what is your name so I put in Randal and it says hello randal . And thats it Its supose to say Hellok Randal! How good of you to be here Thanks betsy

      betsyt

      your code is right, but you are getting caught when you try to "compare" the name entered AND the value RANDAL.

      Try this

      #!/usr/bin/perl print "What is your name?"; $name = <STDIN>; chop($name); if ($name =~ /RANDAL/i) { print "HELLO, RANDAL! HOW GOOD OF YOU TO BE HERE\n"; } else { print "Hello, $name!\n"; }

      This is the same code, except on line 5, we change the eq to =~ /RANDAL/i. This uses a Regular Expression to match the case. If you want to test your script type in RANDAL (in the same case as in the script, not randal, but RANDAL), and it will work fine for you.

      !/usr/bin/perl print "What is your name? "; $name = <STDIN>; CHOP($NAME); IF ($NAME EQ "RANDAL") { PRINT "HELLO, RANDAL! HOW GOOD OF YOU TO BE HERE!\n"; } ELSE { PRINT "HELLO, $NAME!\N"; #ORDINARY GREETING }

      This code works fine, but when you get the prompt "What is your name?" type RANDAL and it will work correctly for you.

      HTH

      - f o o g o d

      --- ruining the bell curve for everyone else ---