Perl array multisorting

perl

PHP includes a native function array_multisort. I miss that in Perl. There’s not as many native functions in Perl to work on arrays, so for a critical project I needed to come up with a different solution.

I decided at first to use just one array, for the same purpose.

Let’s say I have the following arrays:

1 – some_string
2 – some_other_string
4 – some_other_random_string
3 – some_other_random_string_again

And I wanted to order them by the first array, with the numbers. Firstly, you need to check that warnings are turned off in Perl, as you’ll often get “warning is numeric” when running your program.

In the end, I created a new array, let’s called it ‘sorted instances’

my @sorted_instances = ();

# When looping through my previous results, push to the new array, where $1 and $2 match the previous two arrays. #
foreach (@unsorted_instances) {
push @sorted_instances, “$1,$2”;
}

Now the magic which sorts the arrays:
@sorted_instances = sort { $a <=> $b } @sorted_instances;

Confirm it works well:
foreach (@sorted_instances) {
print $_;
print “\n”;
}

Messy, but it works.

puppet failures due to “dnsdomainname: Unknown host”

linux, puppet, selinux

When I was trying to start puppet, I had the following message:
[root@m03 puppet]# service puppet start
Starting puppet: dnsdomainname: Unknown host
dnsdomainname: Unknown host

Even though puppet started successfully. I checked my /etc/hosts file as puppet looks up DNS from there, everything looked fine. I also disabled selinux as that had been recommended on another blog. That might work for you, but didn’t do much for me.

Trying to sign my certificate was proving to be the same issue as well, rendering my puppet setup completely useless:
/usr/sbin/puppetd –waitforcert 30
dnsdomainname: Unknown host
dnsdomainname: Unknown host

I decided to check on the puppet master to see if my signature request had successfully hit the master:
puppet cert list –all | grep -i m03
…but no joy there.

When the dnsdomainname error comes up, the obvious answer is that the DNS is not resolving and it turns out that my puppet install is using an extra DNS entry to connect to the master. I compared an entry on another machine in /etc/resolv.conf, added that to the new machine; ran:
/usr/sbin/puppetd –waitforcert 30

…then the catalog ran successfully.