Perl, Perl 5, Science, Programming/Coding

DevOps in Perl? Consider Rex.

Rex is a ‘Deployment & Configuration Management’ also knows as DevOps framework. Interestingly, it is in Perl, for Perl language. There is Ruby’s Chef & Puppet, Python’s Ansible, and Perl also has those frameworks too, but here I’m pointing to Rex because it will be much more familiar to Puppet, Chef and Ansible users in syntax and workflow perspectives.

Why do this in Perl?

Perl itself has been designed and well known for its powerful features on sysadmin tasks. Combine with this kind of framework, you are just gonna be much happier on getting the job done. Fortunately, if you are trying to opt to write ‘maintainable and long-term modules/scripts’ without using Rex, Modern Perl as a guideline should help you doing so, and CPAN with much lesser code in general.

Perl, Perl 5

Perl: Subroutine signatures

Perl 5.20 experimental feature

Simplest example:

use strict;
use warnings;
use v5.20;
use features 'signatures';

sub add($a, $b) {
    return $a + $b;
}

say add(2,2); # 4

Convenient right? Compared to this –

use strict;
use warnings;
use v5.20;

sub add {
    my ($a, $b) = @_;
    return $a + b;
}

say add(2,2); # 4

How about default arguments?

This can be done with –

use strict;
use warnings;
use v5.20;
use feature 'signatures';

sub add($a, $b = 20) {
    return $a + $b;
}

say add(10, 90); # 100
say add(10); # 30

Neat huh? 🙂