F
freesoft12
Hi,
Given a list containing various UNIX directory paths:
@list = qw(
/home/bart
/home/bart/foo
/usr/lib/
/home/bart/foo/xyz
/home/bart/foo/xyz/live.cpp )
I want to trim this list to contain:
@list = qw(
/usr/lib/
/home/bart/foo/xyz/live.cpp )
Is there a better way than this possibly n^2 algorithm below.
my @to_be_removed_indices = ();
for (my $index=0; $index < #list; ++$index) {
my $current_item = $list[$index];
++$index;
for (my $j = $index; $j < $#list; ++$j) {
if ($current_item =~ m/$list[$j]/) { # is the current item a
substring of another
push (@to_be_removed_indices, $index); # schedule its removal
last; # break
}
}
# Remove matched items
Regards
John
Given a list containing various UNIX directory paths:
@list = qw(
/home/bart
/home/bart/foo
/usr/lib/
/home/bart/foo/xyz
/home/bart/foo/xyz/live.cpp )
I want to trim this list to contain:
@list = qw(
/usr/lib/
/home/bart/foo/xyz/live.cpp )
Is there a better way than this possibly n^2 algorithm below.
my @to_be_removed_indices = ();
for (my $index=0; $index < #list; ++$index) {
my $current_item = $list[$index];
++$index;
for (my $j = $index; $j < $#list; ++$j) {
if ($current_item =~ m/$list[$j]/) { # is the current item a
substring of another
push (@to_be_removed_indices, $index); # schedule its removal
last; # break
}
}
# Remove matched items
Regards
John