note
nvivek
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.
<p>
Initial ( First ) callback of R() function:<br>
$_='x55x666x7777x1x'; $_=undefined;<br/>
Inside code, after evaluating s/(\d+)// ? $1 + R() : 0;<br/>
$1=55; #immediately after executing s// command<br/>
Second callback of R():<br/>
$_='xx666x7777x1x'; $1=55;<br/>
Inside code, after evaluating s/(\d+)// ? $1 + R() : 0;<br/>
$1=666; #immediately after executing s// command<br/>
Third callback of R():<br/>
$_='xxx7777x1x'; $1=666;<br/>
Inside code, after evaluating s/(\d+)// ? $1 + R() : 0;<br/>
$1=7777; #immediately after executing s// command<br/>
Fourth callback of R():<br/>
$_='xxxx1x'; $1=7777;<br/>
Inside code, after evaluating s/(\d+)// ? $1 + R() : 0;<br/>
$1=1; #immediately after executing s// command<br/>
Fifth callback of R():<br/>
$_='xxxxx'; $1=1;<br/>
Inside code, after evaluating s/(\d+)// ? $1 + R() : 0; <br/>
# no callback executed as ( there are no digits ) pattern not matched<br/>
$1=undefined; #immediately after executing s// command<br/>
# after prints 'xxxxx' and '1' for fifth callback<br/>
# after prints 'xxxxx' and '1' for fourth callback<br/>
# after prints 'xxxxx' and '1' for third callback<br/>
# after prints 'xxxxx' and '1' for second callback<br/>
# after prints 'xxxxx' and '1' for first callback<br/>
</p>
<br/>
Kindly regret me for format. I unable to get exact stack of recursive calls for presentation.
1009091
1009092