문제

The following is the code that I tried to execute

$a=0;  
if($a==0){die  print"zero"};  

and I get output as follows

1 at test.pl line 2  
Zero  

I am wondering what is 1 that is printed first, is it something like die is printing the value returned by the if statement? Any help would be appriciated

도움이 되었습니까?

해결책

In

die print "zero";

die will use the return value of print "zero";, which is 1, as its argument. So you see the 1 at ... message.

By default, the STDOUT of interactive program is line buffered, but STDERR is unbuffered, that is why you see the 1 at ... (on stderr) first, and zero (on stdout) later. If you change that print "zero" to print "zero\n", you will see zero comes first.

다른 팁

Actually, print function returned a 1 which die promptly inserted into its error message.

Control never returns to the if stmt.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top