in reply to strange behaviour in perl ..please explain
You have problems understanding where your argument lists end. It would help you to use parens around your arguments.
print"yes",print"no" if ($var);
means
print( "yes", print("no") ) if ($var);
1. The inner print outputs no.
2. The outer print outputs yes and the return value of the inner print (1 for success).
print"yes",exit ,print"no" if ($var);
means
print( "yes", exit(), print("no") ) if ($var);
Arguments are evaluated from left to right, so
1. "yes" is placed on the stack
2. exit is evaluated and causes perl to exit.
3. The inner print never gets to execute.
4. The outer print never gets to execute.
print"yes";exit ,print"no" if ($var);
means
print"yes";
exit(), print("no") if ($var);
Line breaks and the lack thereof are not significant to Perl, so
1. print("yes") is executed unconditionally.
2. exit is evaluated and causes perl to exit.
3. print("no") never gets to execute.
print"yes";print"no",exit if ($var);
means
print"yes";
print( "no", exit() ) if ($var);
1. print("yes") is executed unconditionally.
2. "no" is placed on the stack
3. exit is evaluated and causes perl to exit.
4. The second print never gets to execute.
|
|---|