Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: regex: extract multiple number of date patterns from certain lines

by Random_Walk (Parson)
on Mar 04, 2009 at 19:34 UTC ( #748293=note: print w/ replies, xml ) Need Help??


in reply to Re: regex: extract multiple number of date patterns from certain lines
in thread regex: extract multiple number of date patterns from certain lines

Hi Marshall

I do need the initial date, this is for of a logfile parser that captures these dates and sends them up the line to a monitoring application that then compares the timestamp date to the processed dates and raises an alarm a processed dates was too old.

The crux of the matter is that my log file parser has one shot at each log line with a regex and the matched parts are then passed up to the next stage, I want to get as much done in the regex as possible/reasonable, partly on the principle of keeping monitoring close to the monitored and partly for pure bloody minded IT geek fun.

sadly the main constraint of this problem is one line of regex, code is cheating!

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!


Comment on Re^2: regex: extract multiple number of date patterns from certain lines
Re^3: regex: extract multiple number of date patterns from certain lines
by Marshall (Prior) on Mar 04, 2009 at 22:00 UTC
    So, if I understand this correctly, you are saying that my code works, but there is some constraint that it has to be in one single regex? If that's the case, then we are into some obfuscated code problem and this is perhaps the wrong place?

    If we are talking about clarity and performance, then that's different. Fewer lines of Perl code doesn't always equal faster performance. I simplified this stuff like must match exactly 4 times, etc. This speeds up the regex engine. As far as clarity goes, I would struggle to be more clear (I'm not a guru).

    If you are interested in performance, then measure and test performance (run benchmarks).

    Counting the number of lines of source code is a relatively poor predictor of actual code performance.

    Update: Well it just took some few seconds to get a negative vote on this post. I was genuinely trying to help with the original problem. I don't understand this requirement for "one line". I think that benchmarking and testing is the right way to go. I would be happy to help in this regard.

      Hi Marshall

      There is actually a constraint that it has to be a single regex, see my answer to Ikegami at Re^2: regex: extract multiple number of date patterns from certain lines to see more of the context in which I am operating.

      As for XP, I did not vote you down but there are some grumpy monks around with itchy trigger fingers, I got -- for every single reply in this thread. Don't worry about it too much, sometimes you get a little hit but is normally tends upwards.

      Cheers,
      R.

      Pereant, qui ante nos nostra dixerunt!
        Hi, I am trying to be helpful, not just argumentative just for the sake of arguing. I looked at this:
        http://search.cpan.org/~rcaputo/POE-1.003/lib/POE/Wheel/FollowTail.pm#Filter

        I have no experience at all with this module. But it looks like you can call a sub when a new line appears and that sub can do what it wants with that line. Maybe my impression is wrong somehow..That's always possible!.

        I do have some experience with regex (and I'm not a regex guru by any means!). But my experience with this is that 2 regex's that don't backtrack, don't use fancy look forward features, will run faster than a single fancy regex. There are also differences between say Perl 5.6 and Perl 5.10 regex engines! Perl 5.10 is much faster if that matters to you or you can take advantage of that.

        Your problem: date1 garbage qualifying_text date2,date3,date4... fits very nicely into the algorithm of skip the lines that don't have the qualifying_text and use match global for the dates on the lines that do have the qualifying_text.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-08-30 06:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls