Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Unique values in array

by DigitalKitty (Parson)
on Jun 27, 2003 at 15:20 UTC ( [id://269617]=note: print w/replies, xml ) Need Help??


in reply to Unique values in array

Hi Anonymous Monk.

Since you did not wish to print an array element that occured more than once (unique values only), this will work:

#!/usr/bin/perl -w use strict; my @array = ( 2, 4, 5, 5, 7, 8, 21, 22, 22, 30 ); my %count; foreach ( @array ) { $count{$_}++; } foreach ( @array ) { print "$_ " if $count{$_} < 2; } Output: 2 4 7 8 21 30

Hope this helps,
-Katie.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://269617]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 04:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found