The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help using SED to comment XML elements J-Hon Shell Programming and Scripting 4 06-03-2009 02:42 PM
Forrester’s 4 Elements… iBot Complex Event Processing RSS News 0 08-12-2008 03:40 PM
just want certail elements frenchface Shell Programming and Scripting 1 05-10-2008 10:38 PM
Map - printing all elements - why? dhanamurthy High Level Programming 0 04-14-2008 02:19 PM
Check host file for duplicate entries ThreeDot Shell Programming and Scripting 4 01-21-2008 07:16 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 3 Weeks Ago
james94538 james94538 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 11
check duplicate elements

hi
if i have arry with lots of intergers , how to check if there is duplicate integers
in perl ?

say I ahve @intergers=( 1,2,3,3,4,5,4,99,99,100)
  #2 (permalink)  
Old 3 Weeks Ago
durden_tyler's Avatar
durden_tyler durden_tyler is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 537
If you just want to check (and maybe list) multiple occurrences, then:

Code:
$
$ perl -le '@x = (1,2,3,3,4,5,4,99,99,4,4,3,3,100); foreach $i (@x){$y{$i}++};
            print "Multiple occurrences are: "; foreach (keys %y){print if $y{$_}>1}'
Multiple occurrences are:
99
4
3
$
$
tyler_durden
  #3 (permalink)  
Old 3 Weeks Ago
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
Code:
my @intergers=( 1,2,3,3,4,5,4,99,99,100);
map {$hash{$_}++} @intergers;
print join " -- ", grep {$hash{$_} == 1} keys %hash;
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0