Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^3: Limiting number of regex matches

by davido (Archbishop)
on Sep 25, 2012 at 22:23 UTC ( #995643=note: print w/replies, xml ) Need Help??

in reply to Re^2: Limiting number of regex matches
in thread Limiting number of regex matches

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.


Replies are listed 'Best First'.
Re^4: Limiting number of regex matches
by Marshall (Abbot) on Sep 25, 2012 at 22:56 UTC
    I would personally consider a "warning" as an error even if it is the first one.

    I don't see any really significant disagreement here. I ran your code and it it works. And you ran my code and it works.

    Ok, there are different assumptions as to data set size, etc. But at the end of the day, the OP got two great ideas and he/she can try them both and see what happens in the particular application.

    I claim mutual success! We both did a good job.

      No disagreement whatsoever. I was just clarifying.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995643]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2018-06-20 21:24 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.