in reply to Re: Printing two variables in the same line
in thread Printing two variables in the same line

Let me elaborate:
if ($student = "") {print "Cannot find that student, try again\n";}
Says, essentially, if the result of assigning the value "" to $student is true....

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:

if ($student eq "") {print "Cannot find that student, try again\n";} ## OR, Better unless ($student) {print "Cannot find that student, try again\n";}
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).

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.

radiantmatrix
require General::Disclaimer;

Replies are listed 'Best First'.
Re^3: Printing two variables in the same line
by JustLikeThat (Initiate) on Oct 07, 2004 at 22:00 UTC
    Thank you for taking the time to elaborate and the examples you gave. It was a great help!!!