Monday, May 21

a perl idiom i really like

Turn elements of a list into keys of a hash using map.

my %stop = map { $_ => 1 } ('temp', '..', '.', '');

Which is a lot like saying:

my %stop = ( 'temp' => 1, '..' => 1, '.' => 1, '' => 1);

But much prettier for longer lists.