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

Hi,

I have an array structure as given below

$array1 = [[ 'NY01:080721:13784', 'NY01:080721:54139', '15', '368531', 'NF', '5', '10' ],[ 'NY01:080721:13784', 'NY01:080721:54139', '15', '368534', 'CO', '5', '10' ],[ 'NY01:080721:13784', 'NY01:080721:54181', '10', '368741', 'NF', '4', '6' ],[ 'NY01:080721:13784', 'NY01:080721:54181', '10', '368742', 'NF', '6', '0' ],[ 'NY01:080721:13784', 'NY01:080721:54177', '10', '368756', 'NF', '10', '0' ],[ 'NY01:080721:13784', 'NY01:080721:54179', '10', '368781', 'NF', '10', '0' ],[ 'NY01:080721:13784', 'NY01:080721:54178', '10', '368817', 'NF', '10', '0' ],[ 'NY01:080721:13784', 'NY01:080721:54178', '10', '368729', 'NO', '0', '0' ]];

The array contains value1,value2,value3,value4,value5,value6,value7 From the above array, how can I eliminate duplicate entry based on the value1,value2 and value3.and Result should store as

$array1 = [[ 'NY01:080721:13784', 'NY01:080721:54139', '15', '368534', 'CO', '5', '10' ],[ 'NY01:080721:13784', 'NY01:080721:54181', '10', '368742', 'NF', '6', '0' ],[ 'NY01:080721:13784', 'NY01:080721:54177', '10', '368756', 'NF', '10', '0' ],[ 'NY01:080721:13784', 'NY01:080721:54179', '10', '368781', 'NF', '10', '0' ],[ 'NY01:080721:13784', 'NY01:080721:54178', '10', '368817', 'NF', '10', '0' ]];

Can anyone please provide a solution for this?
Thanks

Replies are listed 'Best First'.
Re: How to Eliminate duplicate entry
by Corion (Patriarch) on Jul 22, 2008 at 07:16 UTC
Re: How to Eliminate duplicate entry
by ikegami (Patriarch) on Jul 22, 2008 at 07:18 UTC

    Just like in perlfaq4, except the uniqueness constraint is join('|', @{$_}[0..2]) instead of $_.

    my %seen; @array = grep !$seen{ join('|', @{$_}[0..2]) }++, @array;

    Update: Added missing comma.

Re: How to Eliminate duplicate entry
by wade (Pilgrim) on Jul 22, 2008 at 15:44 UTC

    Or, you could ask your teacher for help if you're having trouble getting started.

    --
    Wade