Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a question about arrays, that is closely related to the idea of filtering.

Let us say that we have an array @ary; each element of the array @ary is a string. Let us further stipulate the each string is separated by some arbitrary value, such as a colon.

My problem/question is thus:

With the array $ary, let us say that some of the strings are repeated. How would I get rid of all occurences of the same string? (If it makes it easier to do, you can assume that each string is like this "x:y:z..." and every x element must be unique, where x is the first element; i.e., if two x's repeat, then the two strings can be safely assumed to be the same.)

I ran across this problem, and would greatly appreciate an answer. Thank you.

Replies are listed 'Best First'.
Re: Array Question -- Filtering
by cacharbe (Curate) on Oct 20, 2001 at 20:40 UTC
Re: Array Question -- Filtering
by princepawn (Parson) on Oct 21, 2001 at 06:07 UTC
    or you can use a data structure which never creates duplicates, such as a set.

    Jarko has a few modules, I think Set::Scalar is the one which will work for this.

    If not maybe List::Util or Scalar::List::Util