First off, Use strict warnings and diagnostics. It'll make debugging a lot easier.
Secondly, try removing the finddir("$root$file"); from within the foreach loop. You're exiting the loop after the first iteration.
Update: Oops. Read that wrong. Hang on a sec.
Update 2:
my %config = ( home => '/home/cjf/' );
my %user = ( site_id => 'code' );
my @alldir = finddir("$config{home}$user{site_id}");
print $_, "\n" for @alldir;
sub finddir {
my $root = shift;
chomp $root;
$root = $root . '/' unless ( $root =~ m|/$| );
local *DIR;
opendir DIR, $root or die $!;
my @userfiles = sort grep !/^\.\.?\z/, readdir DIR;
my @direct;
foreach my $file (@userfiles) {
next unless ( -d "$root$file" );
my $dir = "$root$file";
$dir =~ s/^\Q$config{home}$user{site_id}\E//;
push(@direct, $dir);
}
return @direct;
}
That will return all directories in $config{home}$user{site_id} but not go into the sub directories. Is that what you're looking for?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|