Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Friday August 29, 2003
12:09 PM

Finding an employee's birthday with regular expressions

[ #14393 ]

This has been a busy week for me. Aside from being week two on my new job, I've also been housesitting for a friend. Were it not for that, I'd be doing some serious work with my regular expression tokens (latest is $Regexp::Token .03 -- which has broken support for HTML comments, but I don't have time to fix that this week). However, it's been a bit of a blessing because I've had to push it in the back of my mind and this has allowed my subconscious to ponder it.

Imagine a logfile that tracks login information with an employee number, a YYYY-MM-DD date followed by other information. How would you extract data to find out which employees worked on their birthdays? There are plenty of ways to do this, but one way would be to create a regular expression token that examines which employee number was matched in $1, fetches that employee's info, check their birthday, and then match that against the date in the next field. The resulting regular expression could look like this:


One could also create a regular expression that would only match weekends if a date is in YYYYMMDD format. This could be useful for logfile analysis:

if (/date: ($is_weekend)/) {...}

Hopefully, I'll get time to write this up properly next week since no one seems to understand my woefully inadequate documentation :)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.