in reply to How do I un-map this code?
can be written asmy @list = map BLOCK LIST;
my @list; for (LIST) { push @list, do BLOCK; }
So
my @files = map { "$self->{update_dir}/$_" } sort { $a <=> $b } grep { /^\d+$/ && $_ <= $id } readdir $dir;
could be written as
my @files; for ( sort { $a <=> $b } grep { /^\d+$/ && $_ <= $id } readdir $dir ) { push @files, "$self->{update_dir}/$_"; }
If what you have a problem with is really the chaining of all those functions and not map specifically, just reverse the order and use a temporary array to hold the arguments.
So
my @files = map { "$self->{update_dir}/$_" } sort { $a <=> $b } grep { /^\d+$/ && $_ <= $id } readdir $dir;
could be written as
my @temp; @temp = readdir $dir; @temp = grep { /^\d+$/ && $_ <= $id } @temp; @temp = sort { $a <=> $b } @temp; @temp = map { "$self->{update_dir}/$_" } @temp; my @files = @temp;
|
|---|