简体   繁体   中英

Perl output shows on the left side of terminal?

Strangely when I execute a code in Perl, the output always appears on the left side of my command line. For example.

admin@admin-machine:~$ perl my_program
1 2 3 4 5 admin@admin-machine:~$

How do I get it to show output on a line by itself like the following?

admin@admin-machine:~$ perl my_program
1 2 3 4 5
admin@admin-machine:~$

You need to add a newline (\\n) to the end of your print statements. Eg

print "1 2 3 4 5 \n";

Everything is possible assuming you really know what you're doing.

if(0 == fork()) {
        sleep(1);
        print "1 2 3 4 5";
}

s0me0ne@ws:/tmp$ perl print.pl 
s0me0ne@ws:/tmp$ 1 2 3 4 5

I doubt if it helps someone but... Just answering ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM