Phoenix.pm: Three snippets

Doug Miles doug.miles at bpxinternet.com
Fri May 4 11:14:23 CDT 2001


Thanks for the answer Tim.  We came up with the same last night. :)

Tim Ayers wrote:
> 
> >>>>> "W" == Webmaster  <webmaster at azwebs.com> 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 bridge.com)

-- 
- Doug

Encrypted with ROT-26 - all attempts to decrypt are illegal under the
DMCA!



More information about the Phoenix-pm mailing list