Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
You probably know already that subroutines can return either scalar or list values. Perhaps you have written both kinds of subroutine. You also probably understand the significance of scalar and list contexts (Item 12). In an idle moment, you may have even wondered how something like the following works:
sub sorted_text_files {
my $dir = shift;
opendir my ($dh), $dir or die "eh?: $!";
# not relevant to wantarray, but we have to
# add the directory prefix here to make this work
my @files = grep { -T } map { "$dir/$_" } readdir $dh;
sort @files;
}