Says, essentially, if the result of assigning the value "" to $student is true....if ($student = "") {print "Cannot find that student, try again\n";}
The problem with that? $student = "" both returns a false value AND makes $student contain an empty string!
The comparison operators are == for binary values (numbers, mostly) and eq for strings. What you really want is:
That way, $student will still hold the value you expect when you reach your print statement. If you use the latter version, it will also function properly if $student is undefined for some reason ("" and undefined are slightly different, but both false).if ($student eq "") {print "Cannot find that student, try again\n";} ## OR, Better unless ($student) {print "Cannot find that student, try again\n";}
It's a very common mistake, and hard to catch. The above advice to use strict; and use warnings; is sound. Also, learning to use the perl debugger might have helped you here.
In reply to Re^2: Printing two variables in the same line
by radiantmatrix
in thread Printing two variables in the same line
by JustLikeThat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |