in reply to Re: I need some beginners help
in thread I need some beginners help

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

Replies are listed 'Best First'.
Re: Re: Re: I need some beginners help
by foogod (Friar) on Aug 07, 2001 at 00:46 UTC

    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 ---