![]() |
removing duplics in an array
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 |
Re: removing duplics in an array
Jerry Preston wrote:
> 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} }; } -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl |
| All times are GMT. The time now is 06:22 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.