Obfusticated Perl

I am a great fan of Perl as a programming language but there is no doubt that it can be obscure. One of my colleagues discovered the following gem while making changes to a logging script:

my @files =
   map $_->[0],
   sort { $a->[1] <=> $b->[1] or $a->[2] <=> $b->[2] or $a->[0] cmp $a->[1] }
   grep $_,
   map { if (/_(\d+)_(\d{8})\.txt/) { [ $_, $2, $1 ] } else { undef } }
   map { lc } grep { /^(LOGSRV\S+)/i && s/;1$// } @$listing;

It is, of course, completely uncommented and the programmer left the company several years ago.

Detailed unobfustication is left as an exercise for the reader but broadly speaking it filters and sorts of list of files named LOGSERV_sequencenumber_date plus extra bits. There is a bug which will occur if two files have the same sequence number and date...


last updated