tchrist@convex.com (Tom Christiansen) (02/23/90)
I've been running into this a bunch lately, which has taken me to
writing a quick, drop-in replacement for <*.bar> type globbing. I
think I'd really like Larry to look at internalizing file globbing.
I think Piet van Oostrum has sent patches for this.
Here's a routine that is a drop-in replacement for globbing
that DOES NOT INVOLVE multi-level directories, although it
does check for those. It's pretty quick.
sub glob {
local($expr) = @_;
local(@retlist) = ();
local(*METADIR); # paranoia
die "glob: null expr" unless $expr; # assert
if ($expr =~ /\//) {
warn "glob: \"$expr\" has slashes, punting...";
return <${expr}>;
}
$expr =~ s/\*/.*/g;
$expr =~ s/\?/./g;
unless (opendir(METADIR, '.')) {
warn "glob: can't opendir ".": $!";
} else {
@retlist = sort grep(/$expr/o, grep(!/^\./, readdir(METADIR)));
closedir METADIR;
}
return @retlist;
}
--tom
--
Tom Christiansen {uunet,uiucdcs,sun}!convex!tchrist
Convex Computer Corporation tchrist@convex.COM
"EMACS belongs in <sys/errno.h>: Editor too big!"