Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Yesterday I wrote the following "opinion":

| print gets its "arguments in reverse order", similar to C.
| The above call would (in C) look like
|(pseudocode):
| ...
| XPUSH( "\n" );
| XPUSH( $| );
| $|--;               # plus true/false magic
| XPUSH( "second=" );
| XPUSH( $| );
| XPUSH( "first=" );
| PUTBACK;
| call_pv("print", G_ARRAY);
| ...
| (please correct here me if I'm wrong)


which turned out to be completely wrong.
After reading the other posts and looking further
into the topic, I came to the conclusion that perl
evaluates the argument list before calling into a sub-
routine always left-to-right.

This can be shown by reading the deparsed output
from B::Bblock /1/. If used on the following lines:
1: $| = 1; 2: print "first=", $|, " second=", $|--, "\n";
the important output will be:
OP (0x824de58) enter COP (0x81f3290) nextstate #1 $| = 1 SVOP (0x824dc80) const [6] IV (0x8167cdc) 1 PADOP (0x818ae48) gvsv GV (0x8168894) *| BINOP (0x8189398) sassign # COP (0x824c638) nextstate OP (0x8250178) pushmark # 2 SVOP (0x8189428) const [7] PV (0x816881c) "first=" PADOP (0x818c6f0) gvsv GV (0x8168894) *| SVOP (0x818de00) const [8] PV (0x8168828) " second=" PADOP (0x824ff88) gvsv GV (0x8168894) *| UNOP (0x824fe50) postdec [4] SVOP (0x824de38) const [9] PV (0x81688b8) "\n" LISTOP (0x8250150) print # LISTOP (0x824dac0) leave [1]
from where it can be learned that the $| decrement
occurs (postdec [4]) where it should.

Sorry for writing such a mess without checking before :-(

Regards

mwa

/1/ perl -MO=Bblock mysource.pl

In reply to Re: Puzzling $| behavior by mwah
in thread Puzzling $| behavior by saintmike

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (9)
    As of 2015-07-08 05:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (94 votes), past polls