in reply to Problem stripping directory listing

try `find /home/sites/$arg1/users -type d -maxdepth 1`.

this might be the more perlish way...

my $which_site = shift @ARGV or die "Usage: $0 <sitename>\n"; my $home = "/home/sites/$which_site/users"; use Cwd; my $old_cwd = cwd(); # keep current working directory chdir $home or die "Can't chdir: $!\n"; opendir(HOME, '.') or die "Can't opendir: $!\n"; my @users = grep { !/^\./ # skip any .file_or_dir esp . and .. and -d # is it a directory? } readdir(HOME); closedir(HOME); # go back to where we started chdir $old_cwd or die "Can't chdir: $!\n"; print join "\n", @users, '';

Replies are listed 'Best First'.
Re: Re: Problem stripping directory listing
by valdez (Monsignor) on Feb 15, 2003 at 12:04 UTC
Re: Re: Problem stripping directory listing
by jdporter (Paladin) on Feb 15, 2003 at 13:11 UTC
    zengargoyle++ for that. But I don't see why it's necessary to chdir to the directory just to read it. Also, IO::Dir makes things somewhat easier.
    use IO::Dir; my @users = (IO::Dir->new($home) or die "$home: $!")->read; print join "\n", @users, '';
    Update: thanks to zengargoyle's note below. Ooops!
    my @users = grep { !/^\./ and -d "$home/$_" } (IO::Dir->new($home) or die "$home: $!")->read;

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.

      chdir was so i didn't have to do -d "$home/$_" for everything.. your solution would likely include . and .. and any files that happened to be loitering around. not that this is likely the best way to find a list of users anyways =P