[Omaha.pm] Wow! I used map!

Jay Hannah jhannah at omnihotels.com
Wed Apr 6 13:51:05 PDT 2005


I never ever ever use map.

Until today. 

I've played w/ it over the years, but I think this is the first time I've consciously set out to use it.

----------
my $out_dir        = "/datamining/rewards/deliver/sent";
my $in_dir         = "/datamining/rewards/receive/processed/UA";
my $waiting_in_dir = "/datamining/rewards/receive";

my ($dir, @files);
foreach $dir ($in_dir, $waiting_in_dir) {
   opendir(DIR, $dir);
   push @files, map { $_ = "$dir/$_" } readdir DIR;
   closedir DIR;
}

@files = grep { /OMNIERROR/i } @files;
-------------

This'd is a lot less code:

  my @files = `ls $in_dir $waiting_in_dir`;
  for (@files) { chomp; }

but wouldn't have the filenames and forking shells isn't efficient (not that I care in this program)...

opendir, readdir, closedir has always struck me as one of the clunkiest areas Perl.

j



More information about the Omaha-pm mailing list