how to get the non repeated values from an array in perl programming
3 1395
how to get the non repeated values from an array in perl programming
- #!/usr/bin/perl
-
use strict;
-
use warnings;
-
-
my @array=(1,1,2,3,4,5,5,6);
-
-
my @unique = ();
-
-
my %Seen = (); #Hash
-
-
foreach my $elem ( @array )
-
{
-
next if $Seen{ $elem }++; #check the key is exist
-
push @unique, $elem;
-
}
-
-
-
-
print @unique;
-
Try this and Let me Know if it is work.
Regards
RajivGandhi.
- #!/usr/bin/perl
-
use strict;
-
use warnings;
-
-
my @array=(1,1,2,3,4,5,5,6);
-
-
my @unique = ();
-
-
my %Seen = (); #Hash
-
-
foreach my $elem ( @array )
-
{
-
next if $Seen{ $elem }++; #check the key is exist
-
push @unique, $elem;
-
}
-
-
-
-
print @unique;
-
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
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
>...
|
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...
|
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/...
|
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...
|
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 ,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
| |