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.


In reply to Re: strange behaviour in perl ..please explain by ikegami
in thread strange behaviour in perl ..please explain by perlplayer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.