[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Wow! I used map!



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