[EMAIL PROTECTED] wrote:

> I've just started trying to pick up a little perl.
> I'm breezing through "Learning Perl" and reading the perl docs.
>
> Here is some syntax I found a little funny, and I was hoping somebody
> could explain this too me:
>
> opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
> @dots = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR);

@dots = grep ({ /^\./ && -f "$some_dir/$_" } readdir(DIR));

Same thing. What it does is to examine the lements of the list returned by
readdir, the second parameter of grep is the list being examined.  It uses
the boolean exprsession in the block--that the element being examined both
starts with a dot *and* is a directory.  The $somedir/ part of the
expression is necessary because the -x file tests use full paths.  Those
elements that pass both tests are passed into the list that is being
assigned to the array @dots.

Heres a sort of step by step:
foreach elemt of readdir dir
   next unless element beginns with '.'
   push into temp_list if element evaluates as a file
next
assign temp_list to @dots.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to