removing duplics in an array

J

Jerry Preston

Hi!

I am able to remove duplets in a simple array:

@name = grep { ! $name_{ $_ }++ } @name_;

But can I do it for each array in a has of arrays?

@{ $ID{ $id }{ data }} = grep { ! ${ $ID{ $id }{ data }}{ $_ }++ } @{
$ID{ $id }{ data }};

Thanks,

Jerry
 
G

Gunnar Hjalmarsson

Jerry said:
I am able to remove duplets in a simple array:

@name = grep { ! $name_{ $_ }++ } @name_;

But can I do it for each array in a has of arrays?

Yes, of course.
@{ $ID{ $id }{ data }} = grep { ! ${ $ID{ $id }{ data }}{ $_ }++ } @{
------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What do you think you access with that? Why would you like the counter
to be part of the data structure?

Just do like this:

for my $id ('id1', 'id2') {
my %count;
@{ $ID{$id}{data} } = grep { ! $count{$_}++ } @{ $ID{$id}{data} };
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top