p1k3::2007/5/21

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.

All original content on p1k3, unless otherwise noted, is released to the public domain.