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

Re^4: 'Dynamic scoping' of capture variables ($1, $2, etc.)

by nvivek (Vicar)
on Dec 19, 2012 at 05:13 UTC ( #1009495=note: print w/replies, xml ) Need Help??


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

Thanks for your explanation Moritz. I meant $1 value got changed similar to $_ value for better understanding. I know that $_ value getting changed due to substitute operator replaces matched digits to null string. I have a doubt in your example, how $1 value getting changed every recursive call. As per your code, your m// expression will match first digits ( 55 ) at all time as per my understanding. Of course, when I checked the code, it gives $1 value as 55, 666, 7777 and 1 respectively. Kindly give me some detail about it.
  • Comment on Re^4: 'Dynamic scoping' of capture variables ($1, $2, etc.)

Replies are listed 'Best First'.
Re^5: 'Dynamic scoping' of capture variables ($1, $2, etc.)
by moritz (Cardinal) on Dec 19, 2012 at 06:21 UTC
    As per your code, your m// expression will match first digits ( 55 ) at all time as per my understanding

    No, because I used m/../g in scalar context, which remembers the previous match position in pos, and then always returns the next match during subsequent calls.

    Maybe you are more familiar with it in this idiom:

    use 5.010; $_ = 'a123b45c6'; while (m/(\d+)/g) { say $1; }
      Thanks for your explanation. I got it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1009495]
help
Chatterbox?
[ambrus]: overhead transparencies are a nice convenience by the way that mix the two slides, because you can write them in advance and edit them during the presentation easily. but they're not very much in fasion these days.
[ambrus]: you can even print them.
[Discipulus]: ambrus i'm trying out MremoteNG which wrap putty and rdp and many other things..
[Corion]: ambrus: Yes, ideally you would have the ease of overhead projection transparencies and pens drawing on them, combined with the computer generated slide text...
[Corion]: Maybe the solution would be a tablet (with pens), like the Wacom tablets, but you still need good software and need to know how to operate it well in an interactive setting ;)

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2017-09-26 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (293 votes). Check out past polls.

    Notices?