Three snippets

Tim Ayers tayers at
Thu May 3 21:43:30 CDT 2001

>>>>> "W" == Webmaster  <webmaster at> writes:
W> Lastly, I just learned a fileglobbing technique...
W> I was writing:
W> opendir(DIR, $dir);
W> while (readdir(DIR))  {
W>     next if /\./;  # don't want current dir and parent dir
W>     &dosomething_with_file
W> }
W> closedir(DIR);

W> But this could be written as simply as:
W> map { &do_file_or_dir } <$dir/*>;
W> or
W> map { &do_dirs_only } grep {-d} <*>;

W> I don't know why (anyone?...) but when file globbing, the '.' and the '..'
W> do not appear as they do when doing readir(DIR).

The < > operator does UNIX-like filename expansion, so <*> won't match
'.' or '..'.  <.*> will, but then you don't get the non-dot files.
The only way I can think to mimic readdir would be (<.*>, <*>) if you
ever wanted to do that concisely.  See 'perldoc -f glob' for more detail.

HTH and
Hope you have a very nice day, :-)
Tim Ayers (tayers at

More information about the Phoenix-pm mailing list