Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
For clear definition, as $_ value got changed in every recursive call of R() function, $1 value also got changed and in return of every recursive call, the last changed value available and that is the reason for getting '1' 5 times in $1. For better understanding, here below I have shown how that recursive calls and values of $_ and $1 will be.

Initial ( First ) callback of R() function:
$_='x55x666x7777x1x'; $_=undefined;
Inside code, after evaluating s/(\d+)// ? $1 + R() : 0;
$1=55; #immediately after executing s// command
 Second callback of R():
 $_='xx666x7777x1x'; $1=55;
 Inside code, after evaluating s/(\d+)// ? $1 + R() : 0;
 $1=666; #immediately after executing s// command
  Third callback of R():
  $_='xxx7777x1x'; $1=666;
  Inside code, after evaluating s/(\d+)// ? $1 + R() : 0;
  $1=7777; #immediately after executing s// command
   Fourth callback of R():
   $_='xxxx1x'; $1=7777;
   Inside code, after evaluating s/(\d+)// ? $1 + R() : 0;
   $1=1; #immediately after executing s// command
    Fifth callback of R():
    $_='xxxxx'; $1=1;
    Inside code, after evaluating s/(\d+)// ? $1 + R() : 0;
    # no callback executed as ( there are no digits ) pattern not matched
    $1=undefined; #immediately after executing s// command
    # after prints 'xxxxx' and '1' for fifth callback
   # after prints 'xxxxx' and '1' for fourth callback
  # after prints 'xxxxx' and '1' for third callback
 # after prints 'xxxxx' and '1' for second callback
# after prints 'xxxxx' and '1' for first callback


Kindly regret me for format. I unable to get exact stack of recursive calls for presentation.

In reply to Re^2: 'Dynamic scoping' of capture variables ($1, $2, etc.) by nvivek
in thread 'Dynamic scoping' of capture variables ($1, $2, etc.) by AnomalousMonk

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
  • Outside of code tags, you may need to use entities for some characters:
            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 making s'mores by the fire in the courtyard of the Monastery: (4)
    As of 2014-09-21 02:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (165 votes), past polls