in reply to Help ! New in perl and cgi

Perl and CGI together eh? Well that is a hard match to pull off if you are new to programming

I would suggest looking through our tutorials. Many of the elder monks have written good stuff for doing things

However, looking at your code. Well unless my dyslexia is kicking in; you have your "N/A"s without quotes.

Start using "use strict" and "use warnings" they are your friends and will point out problems for you. Your NA issue would have been reported to you.

You made this harder then it needs to be. Why not simply read in the line, then have:

if ($comment1 eq " ") { $comment1 = "n/a"; } if ($comment2 eq " ") { $comment2 = "n/a"; }

Then you can have 1 print statement

Some friendly advice. Pick up either Learning Perl or Begining Perl. They should help you with some examples on doing things.

As I said Learning CGI and Learning Perl is hard to do at the same time. You probably should have gotten comfortable with Perl before doing the CGI class. Good luck and don't get discouraged. Perl is a fun language!

Replies are listed 'Best First'.
Re: Re: Help ! New in perl and cgi
by britney (Acolyte) on May 22, 2002 at 05:24 UTC
    Hi Marza, I tried your code and it did not work but if i replace eq with =~
    if ($comment1 =~ " ") { $comment1 = "n/a"; } if ($comment2 =~ " ") { $comment2 = "n/a"; }
    Then it run but all of the comeent1 and comment2 are n/a . Do you know why ? Thanks for reading
      if ($comment1 =~ " ") { # reads: if comment1 *HAS* a space ... } if ($comment1 !~ " ") { # reads: if comment1 *DOESN'T HAVE* a space ... } if ($comment1 eq " ") { # reads: if comment1 *IS* a space ... } if ($comment1 ne " ") { # reads: if comment1 *IS NOT* a space ... } if ($comment1 == " ") { # reads: if comment1 *Numerically Equals* a sp +ace # since space == 0, # ==> same as # if($comment1 == 0){ ... } ... } if ($comment1 != " ") { # reads: *Numerical* not equal to... ... }
      Hope this helps,,,

      PS: As Marza suggested, the llama book is a good book.

      Update: Added the other cases.