"" <> wrote:
> 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 )
That isn't a complete enough specification. What if there is a
/foo/home/bart? How about a /home/bartzilla?
>
> Is there a better way than this possibly n^2 algorithm below.
Almost anything would be better than the below. It doesn't compile.
And once #list is turned to $#list, it does compile but leaves
@to_be_removed_indices empty, so it doesn't what you say you want done.
If you are happy with a wrong answer, then there are much better ways than
n^2 to achieve that.
>
> my @to_be_removed_indices = ();
> for (my $index=0; $index < #list; ++$index) {
> my $current_item = $list[$index];
> ++$index;
You are incrementing ++$index twice, so only even numbered indexes are
being "processed".
etc.
Xho
--
--------------------
http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.