Webreference.com has a excelent tutorial on writing Unix Daemons in Perl.
In Unix, daemons are typically started by the root process when the operating system is initialized, and run in the background indefinitely. Daemons typically spend most of their time waiting for an event or period when they will perform some task. (….) In this tutorial, we’ll learn how easy it is to turn a Perl script into a daemon process.
Its been around for a while, but it would appear that I neglected to blog it when I first saw it. Now that I’ve needed the info, I figured I’d better save it for future reference.
I’ve had a look at the IPTables::IPv4 module from CPAN recently for a job I’m doing. I’ve had a lot of trouble getting it to compile/install on some machines, so I thought I’d share what I’ve found…
The major problems I’ve found relate to the “make test” stage of the install. Firslty, Time::HiRes isn’t listed as a dependency of IPTables::IPv4, bit it needs to be installed otherwise “make test” will fail. I also installed “Bundle::CPAN” to ensure that the modules required for building and installling other modules were present and up to date. “make test” will also fail if there are no iptables rules currently set on our machine, so set up some sample rules before you try a “make test”.
I’ve done the install on a couple of machines now, and eventually got an install working on all of them. The above represents the modules which I know defiantely have helped. On the machines where I’ve had problems I’ve also tried installling the “Error” module and “ExtUtils::MakeMaker”, they didn’t actually seem to fix the problem, but might have contributed to a working solution.
Finally, a gotcha…. Running “make test” will flush all of the existing IPTables rules before it tests. If you’re on an SSH connection this will obviously result in your connection being dropped. “make test” does back up the existing IPTables rules before flushing them, and attempts to restore them afterwards. However I’ve found that rules in the NAT table aren’t restored. I’ve had to resort to the local console to run “make test” successfuly, but there may be other ways around this.
Well, the AFL has started up again, so its time to dust off the trusty Perl script from last year.
Good news is that the AFL hasn’t changed their web site for this season, so no changes to the script are required there. The other REALLY good news is that there’s now 24 experts rather than 20, which means the script has a bot more info to work with. To cope with the extra tipsters, you’ll need to change the following lines in the script.
$MIN_GAME_TIPS = 22;
$MAX_GAME_TIPS = 24;
After Lunch Damian Conway addressed Linux.Conf.Au presenting “Perl 6 in a nutshell”. Essentially, although Perl 5 is great, the source code is becoming very difficult to work with, and the language syntax is coming convoluted at times. So Perl 6 was created to learn from past mistakes, and apply hindsight to the design of Perl. In many areas the language and syntax needed a rethink.
Perl 6 runs on a new platform called Parrot, which is a new virtual machine for Perl, guaranteed to be faster than the Perl 5 interpreter. Although its currently 10 times faster than Perl 5, they expect it to slow down as they add more language featured before release, but overall the target is for at least 2 times faster. Parrot will also run Perl 5, Java and Python, and interconnect the languages. They also want Python to run faster on Parrot than it does natively. Also, because Perl 5 will run on Parrot, and can be called by Perl 6 code everything on CPAN will still work under Perl 6.
Some language differences in Perl 6. The dereferencing operator -> becomes a . to fit more closely with other languages.
There are also new syntax rules for sigils (the $ (scalar), % (hash), or @ (array) before variable names). Now, no matter what the context, you always use the same sigil with hashes and arrays. Previously accessing an element of a hash was done with $hash{index}, and the hash itself referred to as %hash, this becomes %hash{index} and %hash, in Perl 6, much simpler.
Perl 6 now supports Unicode. Both source code and data are assumed to be Unicode by default, but ASCII is still supported where required.
There is a new data type called a junction which is a single scalar that acts like several scalar values. This sounds weird but it allows you to write some really simple code such as…
if (any(@numbers) > 10) { … } #True if any of the numbers in the array are less than 10.
if (one(@roots) != 0) {…} #True if one of @roots is not zero.
Perl 5 also supports multiple comparisons, such as…
if (1 < $x < 10) {…} #True if $x is between 1 and 10.
There is now a ~~ or “generic smart match” operator. Given two values will try to find the most intelegent way to compare them, This means that you no longer have to remember to use == for numbers and eg for strings. This is also a lot like VB’s type coersion features.
There is now no need to break indentation on here documents. Heredocs can be indented in the code without indenting the document contents.
Subroutines can now have parameter lists (finally), and parameters can be strongly typed.
Perl 6 also has a switch statement. Syntax is as follows…
Given $val {
When something { }
When soimethingelse {}
Default {}
}
For loop syntax is now also modified to be just “for LIST BLOCK” so …
For @array -> $value { … }
.. is now valid syntax. Not to mention fairly easy to read.
Finally in Perl 6 classes are declared explicitly “class DogTag { … }” and may now have proper constructors and destructors.
All in all Perl 6 looks to be a significant improvement to Perl 5, but it does still retain its line noise look from Perl 5. The main problem is that some of the bits of noise now mean different things than they did in Perl 5, which is a little off putting. Its really inspired me to take a look at Python instead.
Via a Perl Monks post, comes a couple of things that might be handy. First is a pointer to Net::EasyTCP on CPAN, which allows you to “Easily create secure, bandwidth-friendly TCP/IP clients and servers”. The other is a recommendation to check out Lincoln D. Stein’s Network Programming with Perl book. Both of which could be handy at some point.
Teodor Zlatanov explains the wonders of Inversion lists.
So what are inversion lists? Inversion lists are best described as a condensed summary of a bit string. They are similar to a simple run-length encoding of data, though there are some differences.
Let’s look at an illustrative example. Suppose you want to encode the bit string “1110011.” An inversion list would store a list of three numbers: 0, 3, 5. All we store is the start position of the 1s, then the start position of the 0s, then the position of 1s again, and so on until the bit string is over.
Neat idea.
LinuxPlanet reviews ActiveState’s Komodo editor.
ActiveState had been doing Perl tools since day one and up until early 2000 didn’t have an integrated development environment product. After numerous customer requests, the team decided that since the company was expanding from a “Perl for Windows” shop to a company that supported a variety of programming languages, it was a good time to take on the task. Thus, was born Komodo.
Looks like its worth checking out. I’m still rying to find a good editor for use with PHP, if it supported Perl as well that’d be great!
A while back I posted my perl script for football tipping, then later updated it with some new features. Subsequent web site redeigns by the AFL meant that the HTML parser has since changed, and I also added a feature to predict the winning margin for the Footy Park match (something that one of the comps I’m in requires). Finally the script grew a subroutine to help correct typo’s in the team names on the expert tips page. The final version is available here.
So, after a promising start, how did the script fare? After the 22 minor rounds of the season, my perl script tipped 120 winners (avg. 5.45 per week), of a maximum 176. Past season’s suggest that an average of about 5 will win it for you, but in one comp I finished 5th while the winner scored 123 (avg. 5.59). Although the final results aren’t in yet, I expect to be further off the pace in our work comp due to some excellent tipping by the leaders.
If nothing else, it proves that 143 lines of Perl will produce a better result than a coin (when I tipped with a coin a few years back I got 90 for the season). It also proves that a small Perl program that knows nothing about the game is likely to tip better than most footy fans 
ONLamp.com has a handly article on writing regexp’s that a mere motal can understand and maintain.
Regular expressions are hard to write, hard to read, and hard to maintain. Plus, they are often wrong, matching unexpected text and missing valid text. The problem stems from the power and expressiveness of regular expressions. Each metacharacter packs power and nuance, making code impossible to decipher without resorting to mental gymnastics.