Anonymous user
Walk a directory/Non-recursively: Difference between revisions
Walk a directory/Non-recursively (view source)
Revision as of 00:52, 28 September 2012
, 11 years ago→{{header|Perl}}: also glob() function
(add emacs lisp) |
(→{{header|Perl}}: also glob() function) |
||
Line 496:
say for grep { $pattern } readdir $dh;
closedir $dh;</lang>
Or using globbing
<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}}==
|