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

This is what I have:
@array = ([a,0,b],[c,1,d],[d,1,e],[f,2,h];
I only care about the 2nd field. I want all of the unique values. In other words I want to get 0, 1, and 2. In the script I have they will always be sorted by the 2nd field, so there should be no need to do a sort. Any suggestions? Thanks

Replies are listed 'Best First'.
Re: How do I pull out unique values in a multidimentional array
by dragonchild (Archbishop) on Jun 28, 2001 at 23:15 UTC
    my %unique_values; $unique_values{$_->[1]}++ for @array; print "Key $_\n" foreach keys %unique_values;
Re: How do I pull out unique values in a multidimentional array
by dimmesdale (Friar) on Jun 28, 2001 at 23:53 UTC
    This isn't tested, but it should do the trick
    map { $results[$k++] = $_->[1] if !$seen{$_->[1]}++ } @array;
Re: How do I pull out unique values in a multidimentional array
by repson (Chaplain) on Jun 29, 2001 at 11:31 UTC
    If you are willing to rely on the values being sorted and don't want to create a hash of the values like the other solutions you could do something like this.
    my @unique; for (@array) { push @unique, $_->[1] unless $unique[$#unique] == $_->[ +1] }
Re: How do I pull out unique values in a multidimentional array
by dragonchild (Archbishop) on Jun 28, 2001 at 23:18 UTC

    Sorry about the above - forgot the <code> tags.

    my %unique_values; $unique_values{$_->[1]}++ for @array; print "Key $_\n" foreach keys %unique_values;

    Originally posted as a Categorized Answer.