Beginner wrote:
> On 18 Sep 2006 at 15:05, John W. Krahn wrote:
>>
>>my $dir = '/tmp';
>>
>>opendir my $dh, $dir or die "Cannot open '$dir' $!";
>>
>>print "$dir\n",
>>      map !/\A\.\.?\z/ && -d "$dir/$_" ? "$dir/$_\n" : (),
>>      readdir $dh;
> 
> That's looks nice John...but what is actually happening here. Some 
> sort of negation of \A (is that a character class?) and a directory 
> and/or something with a newline???

perldoc perlre
[snip]
       Perl defines the following zero-width assertions:

           \b  Match a word boundary
           \B  Match a non-(word boundary)
           \A  Match only at beginning of string
           \Z  Match only at end of string, or before newline at the end
           \z  Match only at end of string
           \G  Match only at pos() (e.g. at the end-of-match position
               of prior m//g)


"readdir $dh" returns a list of entries from the $dir directory.  Inside map()
each entry is aliased to the $_ variable.  The contents of $_ are matched
against the pattern /\A\.\.?\z/ which will only match if $_ contains '.' or
'..' and if it does NOT match then "$dir/$_" is tested to see if it is a
directory and if it is then the string "$dir/$_\n" is returned.



John
-- 
use Perl;
program
fulfillment

-- 
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