Walk a directory/Non-recursively: Difference between revisions
Content added Content deleted
(add emacs lisp) |
(→{{header|Perl}}: also glob() function) |
||
Line 496: | Line 496: | ||
say for grep { $pattern } readdir $dh; |
say for grep { $pattern } readdir $dh; |
||
closedir $dh;</lang> |
closedir $dh;</lang> |
||
Or using globbing |
Or using globbing, with the <code><></code> operator, |
||
<lang perl>use 5.010; say while </home/foo/bar/*.php>;</lang> |
<lang perl>use 5.010; say while </home/foo/bar/*.php>;</lang> |
||
Or the same with the builtin <code>glob()</code> function, |
|||
<lang perl>my @filenames = glob('/home/foo/bar/*.php');</lang> |
|||
The <code>glob()</code> function takes any expression for its pattern, whereas <code><></code> is only for a literal. |
|||
<lang perl>my $pattern = '*.c'; |
|||
my @filenames = glob($pattern);</lang> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |