473,325 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

arrays in perl

how to get the non repeated values from an array in perl programming
Jan 7 '08 #1
3 1395
rajiv07
141 100+
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
3,509 Expert Mod 2GB
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
141 100+
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

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

Similar topics

5
by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would...
2
by: windandwaves | last post by:
is there a quick way to compare the results from two arrays and note the differences? I have two identical tables in MySql (backup and current table) and I want to work out the differences between...
19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
3
by: wombat | last post by:
I have a question about using arrays in Perl, involving connecting to MySQL databases. In the past I've used PHP to access databases and I've been playing around now with Perl. In PHP to access...
2
by: rathankar | last post by:
dear friends thanks for the mail sent today i have one more question: 1. since in perl arrays need not be declared, , what is the maximum limit of elements an array could have? 2. in java/ c/...
5
by: Ramon F Herrera | last post by:
I am looking for a good excuse to pick up C++. I have been a satisfied C programmer for years, a language that provides me all the facilities that I need, with ONE exception. I keep on finding...
5
by: enkidu72 | last post by:
Hello everybody , I have a problem with arrays ... I need to get some data from files in some directories . The names of the dirs are something like 12.12344 or 23.34441. Some contains one ,...
3
by: erbrose | last post by:
Hello all! Newbie here, I've been tasked with a fairly intensive project here and my perl skills are still at a minimum so this post may eventually turn into a long one, but I am only going to ask...
3
by: poolboi | last post by:
hi guys, i dunno if this post should be in Perl or MySQL but i'm using Perl DBI to do manupilations now in MySQL i've got problem trying to input 2 arrays of data into 2 fields at the same...
1
by: rgoren | last post by:
Hi, I set up an Axis POJO service and perl cient using SOAP::Lite. I am able to receive all simple types of return values (String, int, etc.) and also arrays (String in the POJO service). The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.