in reply to Re^2: using grep on a directory to list files for a single date
in thread using grep on a directory to list files for a single date
ikegami has already posted an excellent reply, showing exactly how to do it with while. That is probably the best way to solve this particular problem, but I thought I would show you how to use map to filter out elements, for your future reference:
my @array = qw(foo bar baz qux); my @newarray = map { my $foo = $_; $foo =~ s/./\u$&/; # useless example $foo =~ /Ba/ ? $foo : () } grep { /a/ } @array;
The key here is to return an empty list when the condition fails. It's neat that we can do this with map, but it's usually better to use another grep:
my @array = qw(foo bar baz qux); my @newarray = grep { /Ba/ } map { my $foo = $_; $foo =~ s/./\u$&/; # useless example $foo } grep { /a/ } @array;
HTH
|
|---|