perlquestion
uksza
Wise Monks,<br><br>
It's hard to say what I need, so I use some examples:<br>
<readmore title="Little examples">
I have directiories:
<code>
/root
+dir1
+1a
+1b
+dir2
+2a
+2b
+2c
</code>
without exceptions my directiories list shoud look:
<code>
/root
</code>
with exception on /root/dir2/2b:
<code>
/root/dir1
/root/dir2/2a
/root/dir2/3a
</code>
</readmore>
So, I use some code from [id://31503] on [id://32789] and I've made this:
<code>
use File::Find;
my @abs_dirs = qw ( /usr/local/share/locale );
my %abs_dirs;
@abs_dirs{@abs_dirs} = ();
my @OK_dir;
my %all;
find(
sub {
$File::Find::prune = 1, return
if -d and ( exists $abs_dirs{$File::Find::name} );
my $dir = $File::Find::name;
return if -f $dir;
if ( ( grep { $_ =~ m/$dir/ } @abs_dirs ) and ( !exists $all{$dir} ) ) {
$all{$dir};
}
else {
push @OK_dir, $dir;
$File::Find::prune = 1;
return;
}
},
"/usr/local/"
);
</code>
It works, but I wonder if is any better way to do it? I dont't think about usless $all{$dir}, but about totally difrent way.
<br>
Thanks for your help and time,
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-388230">
<br>greetz, Uksza<br><br>
<font size='1'>
Yes, smart people know that fat arrow autoquotes the left argument. But why should you require your code to be maintained by smart people?<div>
<i>Randal L. Schwartz, Perl hacker </i>
</font>
</div></div>
<p><small>2006-02-21 Retitled by [planetscape], as per Monastery [id://341118|guidelines] <br />Original title: 'Directiories without recursion and exceptions'</small></p>