in reply to Get list of first level subdirectories

Simple first level subdirectories list:
my $dir = shift || "client"; my @list = (); for( glob "*$dir*" ){ -d or next; for( glob "$_/*" ){ -d or next; push @list, $_; } } $" = $/; print "@list" __END__ client1/DIR_1 client1/DIR_2 client1/DIR_3 client2/DIR_1 client2/DIR_2 client2/DIR_3 client3/DIR_1 client3/DIR_2 client3/DIR_3


Replies are listed 'Best First'.
Re^2: Get list of first level subdirectories
by itub (Priest) on Jul 21, 2005 at 15:25 UTC
    You don't need the outer loop, because glob can take care of that implicitly. And you can also use grep instead of for to build the list:
    my $dir = shift || "client"; my @list = grep -d, glob "*$dir*/*"; $" = $/; print "@list"
      # 1 2 3 #123456789012345678901234567890123 print join"\n",grep-d,glob(shift)
      33 :)


      holli, /regexed monk/
        I knew someone wouldn't resist the temptation to golf it! ;-) But that wasn't my intention; I just wanted to make the code reasonably concise and clear (according to my definition of clear), and I also assumed that @list would be needed later in the code.