in reply to globing directory names with spaces

Imho glob()bing is ugly anyway. You don't need it. It is much better (again imho) to use grep and readdir, which is also much more portable:

my $dir = shift; my @list = grep /\.java$/ => sub { opendir my $dh => $_[0] or return; my @l = readdir $dh; closedir $dh; return @l }->( $dir ) ;

The subref is of course overhead, but you might want to keep it as named sub for multiple use.

--
http://fruiture.de

Replies are listed 'Best First'.
•Re: Re: globing directory names with spaces
by merlyn (Sage) on Sep 16, 2002 at 15:31 UTC
    The subref is of course overhead, but you might want to keep it as named sub for multiple use.
    Or just eliminate it entirely using a do-block instead of indirecting it with a subroutine:
    my $dir = shift; my @list = grep /\.java$/ , do { if (opendir my $dh, $dir) { my @l = readdir $dh; closedir $dh; @l; } else { () } };

    -- Randal L. Schwartz, Perl hacker