develooper Front page | perl.perl6.users | Postings from November 2018

How to use sub/method 'dir'

Thread Next
From:
Fernando Santagata
Date:
November 24, 2018 21:19
Subject:
How to use sub/method 'dir'
Message ID:
CAJ+jyGiH_QkQUrFMq4Dra459C=_HL2io-_7mKZ+9-4dY=ufMZA@mail.gmail.com
Hello,

I think that I don't understand how the 'test' argument of 'dir' works.
I have a directory 'a', which contains a subdirectory 'b' and a file 'c'; I
want to select only the subdirectories of 'a'.

Using the REPL I tried to ask the content of the directory 'a':

> my @dirs = dir('a')
["a/c".IO "a/b".IO]
> my @dirs = dir('a', test => { .IO.d })
["a/.".IO "a/..".IO]
Why omitting the test the code returns the right list, while adding the
test it returns just '.' and '..'?

If I do the same thing for the top level directory '.' the behavior is
different:

> my @dirs = dir('.', test => { .IO.d })
[".".IO "a".IO "..".IO]

Now I can see the directory 'a'.
If I descend a level, doing a 'cd a', the behavior is consistent with what
I see at the previous level.
I'm confused.

I'm using version 2018.10.

-- 
Fernando Santagata

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About