To be accurate, it does work with or without initializing $count to zero. But on the first iteration, the undefined $count will be treated as though it were zero, and a warning will be generated letting the programmer know that he probably should initialize $count to zero explicitly before using it in the context of a numeric comparison (assuming warnings are enabled, as they probably ought to be).
As for why the example doesn't explicitly use strict, first it seemed that the OP already had a handle on how to declare lexical variables, and second, "Well, because it's a four-line one-line example program I concocted as an example in my Usenet PerlMonks article---duh!"
(I hope the intended humor isn't lost in this post, your point is valid.)
Oh, and you're correct; the process stops as soon as the $limitth match occurs, which is a good approach since it stops extra work from happening. Think of it as the difference between List::Util's first function, and the core's grep.
Dave
In reply to Re^3: Limiting number of regex matches
by davido
in thread Limiting number of regex matches
by eversuhoshin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |