Scott_g wrote at Sun, 22 Jun 2003 15:21:24 -0500: > Hello. I am new to Perl. I used to program in C years ago (not C++ # > etc) > > I have the simplest question. I am running active state perl 5 on Win > XP. > > I'm using OpenPERL Ide 1.0 > > #!k:/perl/bin/perl.exe > # > # Camel-Learning Perl > # Exercise 2-4 > # Input a & b from Console <STDIN> > # Then multiply & print them > # > print "Enter an integer: ",$a=<STDIN>; # This don't work
Perl interpretes this as print( "Enter an integer: ", $a=<STDIN> ); So it can executes print only when both arguments are evaluated first, forcing you to enter $a before you see the prompt. > # > print "Enter an integer: \n"; # Neither does > this $a=<STDIN>; # ... > > This program excerpt above is driving me crazy! I can NOT get the PROMPT > to appear BEFORE the program waits for input. I have tried several > different ways to do this. No matter what I do, the screen stays blank, > until I enter a value, THEN the prompt is printed! This works for me, but > when I get into a larger program, the USER is going to have to read the > PROMPT BEFORE they know what to type in! Try instead the explicit print("Enter an integer: "),$a=<STDIN>; allthough I still would prefer in most cases to write the semicolon instead of the comma (but of course in some cases it's very useful like print("..."),$x=<STDIN> unless defined($x); ) Greetings, Janek PS: $a is a bad name for a variable as it is a global variable used for sortings. (Read perldoc perlvar for details). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]