Hello Monks,
I'm a pathetic newbie trying to slog through the "Camel", with reasonable success so far. Anyway, I cannot figure out one of the examples. From the book:
"The we match any number of characters with .* - but we place another code subpattern in between the . and the * so we can count how many times . matches.
Here is the example:
#!/usr/bin/perl
$_ = "lothlorien";
m/ (?{ $i = 0 })
(. (?{ $i++ }) )*
lori
/x;
$i=10?
So, the increment of $i is right in between the . and the quantifer, * - but $i=10? If it increments whenever the . matches, then I thought $i should be 7. The '.*' would match the whole string, then back up one at a time till the rest of the pattern could match the 'lori' part.
Can someone enlighten me?
PS. The "code sub-pattern" is zero-width; is this why it can sit in a pair of paratheses that is being quanified (by the *). This seems very weird to me.
~stratkid
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.