Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   removing duplics in an array (http://www.velocityreviews.com/forums/t888548-removing-duplics-in-an-array.html)

Jerry Preston 10-17-2004 09:33 AM

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





Gunnar Hjalmarsson 10-17-2004 12:45 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57