perl - why is the shell script executed before the print command?

i'm writing some simple scripts to help me learn perl.

why does the print command get called after the shell script is executed?

the purpose of the shell script is to simply echo to the screen "script run". which is does, but before the print command, you can clearly see the shell script is called after the print command.

print "\ntry and run shell script";
$execute = system("/export/home/reladmin/scripts/tst.ksh") && die "cannot";


OUTPUT:
script run
try and run shell script

you see, this could be a problem when i come to write my proper perl scripts, where i want a shell script to be called and executed before the perl script continues and executes another command.

If you add

$| = 1;

in front of the program. Is it okay now?

Looks like Perl is buffering stdout, can you do the equivalent of fflush?

yes, using $| = 1; works.

i've just googled this flushing business and now i understand.

thanks everyone. and thank you cbkihong.....again.