By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,250 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,250 IT Pros & Developers. It's quick & easy.

arrays in perl

P: 1
how to get the non repeated values from an array in perl programming
Jan 7 '08 #1
Share this Question
Share on Google+
3 Replies


rajiv07
100+
P: 141
how to get the non repeated values from an array in perl programming

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. my @array=(1,1,2,3,4,5,5,6);
  6.  
  7. my @unique = ();
  8.  
  9. my %Seen   = (); #Hash 
  10.  
  11.     foreach my $elem ( @array )
  12.       {
  13.       next if $Seen{ $elem }++; #check the key is exist 
  14.       push @unique, $elem;
  15.       }
  16.  
  17.  
  18.  
  19.       print @unique;
  20.  
Try this and Let me Know if it is work.
Regards
RajivGandhi.
Jan 7 '08 #2

numberwhun
Expert Mod 2.5K+
P: 3,503
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. my @array=(1,1,2,3,4,5,5,6);
  6.  
  7. my @unique = ();
  8.  
  9. my %Seen   = (); #Hash 
  10.  
  11.     foreach my $elem ( @array )
  12.       {
  13.       next if $Seen{ $elem }++; #check the key is exist 
  14.       push @unique, $elem;
  15.       }
  16.  
  17.  
  18.  
  19.       print @unique;
  20.  
Try this and Let me Know if it is work.
Regards
RajivGandhi.
Rajiv,

Being that this is a learning forum, and not a scripting service, we typically require that users show us the code they have tried so we can assist them in getting it correct before just throwing code at them. In the future, please remember this, otherwise you are not really helping the OP learn, but instead are feeding them the answers.

Besides, this sounds suspiciously like a homework assignment and you just did it for them.


pravina2008,

If this IS a homework assignment, then please know that it is against TSDN Posting Guidelines to post your homework here in expectation of an answer.

Next time, please show your code!

Regards,

Jeff
Jan 7 '08 #3

rajiv07
100+
P: 141
Rajiv,

Being that this is a learning forum, and not a scripting service, we typically require that users show us the code they have tried so we can assist them in getting it correct before just throwing code at them. In the future, please remember this, otherwise you are not really helping the OP learn, but instead are feeding them the answers.

Besides, this sounds suspiciously like a homework assignment and you just did it for them.


pravina2008,

If this IS a homework assignment, then please know that it is against TSDN Posting Guidelines to post your homework here in expectation of an answer.

Next time, please show your code!

Regards,

Jeff
Hi numberwhun
I have got your point.I wont do that in future.
Thanks
Regards
RajivGandhi
Jan 7 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.