Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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.


Dave


Comment on Re^3: Limiting number of regex matches
Select or Download Code
Re^4: Limiting number of regex matches
by Marshall (Prior) 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.

      Cheers!


      Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995643]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2014-09-17 12:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (77 votes), past polls