Don't ask to ask, just ask | |
PerlMonks |
Re^3: Limiting number of regex matchesby davido (Cardinal) |
on Sep 25, 2012 at 22:23 UTC ( [id://995643]=note: print w/replies, xml ) | Need Help?? |
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 (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 Section
Seekers of Perl Wisdom
|
|