Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (None)
    As of 2024-04-25 03:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found