[Melbourne-pm] I <3 map & grep
Daniel Pittman
daniel at rimspace.net
Thu Oct 27 08:24:03 PDT 2011
On Wed, Oct 26, 2011 at 22:07, Toby Corkindale
<toby.corkindale at strategicdata.com.au> wrote:
> But perhaps, a little too much..
> I just found myself this:
I would have simplified this so:
> use Config::General qw(ParseConfig);
use Path::Class;
> ...
> opendir(my $dir, $self->sites_dir) or die..;
>
> my %sites = map { $_->{name} => Streuth::Site->new($_) }
> map { { ParseConfig($_) } }
> grep { -f $_ }
> map { File::Spec->catfile($self->sites_dir, $_) }
map { file($self->sites_dir, $_) }
> grep { /^[-_a-zA-Z\d\.]+$/ }
> readdir($dir);
...which gives a richer set of interfaces around the object. You see
more benefit when you do more than just "is it a file", etc, and there
are some internal directory iteration tools if you want.
Daniel
--
♲ Made with 100 percent post-consumer electrons
More information about the Melbourne-pm
mailing list