Posts

Showing posts from July, 2010

Cygwin + syslog-ng

Until I can get a real workstation at work and get off this winblows, Cygwin is my friend.  I am working on some OO programming with PERL and really need to be able to log syslog messages locally. After installing syslog-ng, I couldn't figure out how to run it, till I stumbled on a page that mentioned the syslogd-config command. Initially I had some problems because the /etc/passwd and /etc/group files were not world readable (don't know if that is a side effect of the Legato restore of my laptop or just the default behavior) however a quick " chmod a+r /etc/passwd /etc/group " seemed to help. running syslogd-config yielded this output: > syslogd-ng-config Creating default /etc/syslog-ng.conf file Warning: The syslogd service is already installed.  You can not run both, syslogd and syslog-ng in parallel. Do you want to deinstall the syslogd service in favor of syslog-ng? (yes/no) yes Warning: The following function requires administrator privileg

PERL Array count on Array Reference

PERL has a lot of cool built in operators to find things like number of elements in an array an such ($# ) which are very straight forward when using basic data types. With C I never had a problem with the indirection associated with pointers and dereferencing.  Of course, being the pedantic guy I am, I always used parentheses to excess. Anyway, I was working on some code to retrieve as set of fields back from an Omnibus database and the database function returns a reference to an array of arrays.  I only expect 1 row coming back, but I needed a quick way to tell that.  With a little experimentation I found it was: $#$resultsPTR  Sure it is easy now, but I had to run through a few iterations to figure out just what $# wanted to see. Here is a larger code chunk to put things in perspective, hopefully sanitized enough to  be public: #!/usr/bin/perl # # $Id$ # use strict; use warnings; use diagnostics; use POSIX ":sys_wait_h"; use lib "/packages"; require &

PERL and IPC with one-way pipes

I have a project that I really need to add some parallelism  to increase the speed.  I poked around on the perl.org and managed to cobble together this little bit of code to show how the children worked. This is non-blocking using waitpid. #!/usr/bin/perl # # $Id$ # use strict; use warnings; use diagnostics; use POSIX ":sys_wait_h"; sub main () {     my ($CHILDNUM);     my ($childFhPTR,$FHx, $cPID);     my ($sleeptime,$keepgoing,$nextkid,$linenum,$nextline);     foreach $CHILDNUM ( 0,1,2,3,4 )     {         if ( !defined($cPID = open ($FHx, "-|")) )         {             die "can not spawn child for some reason maybe ($!)";         }                 if ( $cPID == 0 )    # child         {             $sleeptime = int(rand(25));             print STDOUT "I am child ($$) with CHILDNUM ($CHILDNUM) and will be sleeping for ($sleeptime) seconds\n";             sleep $sleeptime;             print STDOUT "This is chil