Perl Monks level bumped

It’s been a while since I hanged out at Perl Monks. Today I followed some link and ended up reading a couple of articles there. I decided to check my status and discovered that I only needed 9 points to achieve the next level – pontiff. 30 daily votes were available, so I voted here and there and gained the points.

Now I am a Pontiff and need 700 points to step up to the top of the ladder – Saint.

Working with named pipes in Perl

The collegue of mine came across a problem that developed into an interesting solution that I decided to share with the world. Actually, I think the world is pretty much aware of the solution, but just in case that I will ever be looking for this solution again, I’ll have it handy here.

The task at hand was to do some processing of the logs on the fly. The syslog was configured to filter the appropriate logs into a named pipe and a Perl script was written to read from the said pipe and do all the processing.

The original piece of code looked something like this:

open (SYSLOG, "<$named_pipe") 
  or die "Couldn't open $named_pipe: $!\n";

while () {
  do_processing($_);
}

close(SYSLOG);

The problem came with syslog daemon restarts. Every time the syslog was stopped, the EOF was sent to the pipe and the script stopped reading it.

Continue reading Working with named pipes in Perl

Daily del.icio.us bookmarks

I think that I should spice up a bit these long lists of links. I’ll be adding some comments once in a while for this posts to be more human friendly. Those posts with a lot of links (lik this one) will be split into a introductory part and the full article, so that the main page of the site won’t get too long to scroll.

First group of links has to do with logic programming in Prolog language. Most of these links I found in the reference list in Ovid’s presentation at OSCON. Ovid was talking about ways of integrating Prolog and Perl. The link to his presentation is the first in the list.

Continue reading Daily del.icio.us bookmarks

Analysis of two perl lines

Today I saw these two lines in one backup script that was written in perl:

my $d = (localtime())[6];
$d = $d=~/[067]/ ? 0 : $d % 2 + 1;

Does this look cryptic to you? Probably not. But I wanted to write something and thought that these two lines won’t be that obvious for everyone out there. So I decided to explain exactly what goes on.

Before I start, I have to say that these are not just any two random lines of perl code. These are very useful lines that provide a short and elegant solution to a rather common problem. Read on if you interested.

Continue reading Analysis of two perl lines