in reply to Re^5: Doing "it" only once
in thread Doing "it" only once

Roy Johnson,
Wow - thanks! That's neat, but I am not sure if it fits the bill. If my understanding of this is correct, it basically ignores subsequent matches if a match has already been found. If that is technically accurate, it fails in that it still checks to see if there is a match before deciding to ignore it.

This really is a meditation about being able to modify the optree (or the p6 equivalent) while the code is running and what you would do with it if you could. I provided the example of removing a conditional block once the condition has been met and the block ran once. This means not even the condition itself is checked, it would just be "gone". This, I am sure, is not the only application.

Cheers - L~R

Replies are listed 'Best First'.
Re^7: Doing "it" only once
by Roy Johnson (Monsignor) on Sep 21, 2005 at 18:35 UTC
    This code illustrates that the op only performs the match once:
    my $type; my $r = qr/(?{print "$type\n"})/; for (1..3) { $type = 'Regular'; /$r/; $type = 'Once only'; ?$r?; }
    On the broader subject of modifying the optree...well, it hasn't really occurred to me very often. The most common reason to do it is to introduce new syntax, which I guess is what you're suggesting, after a fashion. If I were up to it, I would probably want to implement a new operator.

    (update: But there's more to adding syntax than modifying the optree. It's gotta parse, too.)


    Caution: Contents may have been coded under pressure.