in reply to Printing two variables in the same line

Formatting your code will make it a lot easier to read. E.g. :
if ($student = "") { print "Cannot find that student, try again\n"; } else { print "$_ has a" . $student . "\n"; }
Also, you do not need to put a trailing semicolon at the end of your else block. All this does is create an empty statement that does nothing.

Replies are listed 'Best First'.
Re^2: Printing two variables in the same line
by JediWizard (Deacon) on Oct 07, 2004 at 20:53 UTC

    I have been advised by some people I trust, and have a huge ammount of respect for, To always put a semi-colon on the end of every statement, even those at the end of a block. While using a semi-colon on the last statement of a block is not necissary, it can help maintainablity. I can think of a hundered situations where I have gone back and added code into an existing block, and if the semi-colon is not there, when I'm adding to it later, I am likely to forget (until I try to run the code and it doesn't compile).

    May the Force be with you

      Hmm, I don't think I was being clear enough. The author had:

      if { } else { };

      I'm not talking about having a semi-colon at the end of the last statment in a block. I'm talking about having a semi-colon AFTER the closing curly brace at the end of the block.

        I'm not talking about having a semi-colon at the end of the last statment in a block. I'm talking about having a semi-colon AFTER the closing curly brace at the end of the block.

        That was clear to me! Personally I never put a semicolon after a block. But then I often forget to put one at the end of an eval statement. So perhaps if I had a coding style that put a redundant semiclon after all blocks then I wouldn't forget them where necessary?

        Smylers

        Ahh Soo. :-) You are most correct that a semi-colon following the } is quite unnecessary.

        May the Force be with you