Hi,
*Remove duplicate from an array using hash, It will disorder the original position of an array * __CODE__ my @array = qw(11 2 3 4 55 4 3 2); my %hash; map { $hash{$_}++ } @array; @array = keys %hash; print "Array:@array\n"; __END__ *Remove duplicate elelments from an array, It will maintain the original order* __CODE__ @array = qw(11 2 3 4 55 4 3 2); %hash = (); for(my $i=0;$i<=$#array;$i++){ # store the position from array. use array element as key n position as value $hash{$array[$i]} = $i if ( ! exists $hash{$array[$i]} ) ; } @array = (); push(@array, $_) for (sort { $hash{$a} <=> $hash{$b}} keys %hash ) ; print "Array:@array\n"; __END__ Regards, Pritish On Sun, Nov 29, 2015 at 1:09 PM, Jitendra Barik <jbarik...@gmail.com> wrote: > Hi Sunita, > > Please find the code snippet here: > > @array = qw(1 2 3 4 5 4 3 2); > foreach (@array){ > $myhash{$_} = $myhash{$_} + 1; > } > while(($s,$k) = each(%myhash)){ > > push @res,$k; > } > print "Array in unique is : @res\n"; > > Regards, > Jitendra > > On Thu, Nov 26, 2015 at 10:46 PM, Mike Flannigan <mikef...@att.net> wrote: > >> >> See if this meets your needs: >> http://www.arl.wustl.edu/projects/fpx/references/perl/cookbook/ch04_07.htm >> >> >> Mike >> >> >> On 11/25/2015 1:53 AM, beginners-digest-h...@perl.org wrote: >> >> >> >> >> >> Hi >> >> I want to create a unique array . >> >> I have the code below. It is creating a array which will have duplicate >> data . How can I filter duplicate data ? >> >> #!/usr/bin/perl >> >> use Data::Dumper; >> >> >> >> #my $cnt = scalar @$net_int_parsed_output; $net_int_parsed_output = >> [lif_1 ,lif_2,lif_3,lif_4,lif_1,lif_2]; foreach my $n >> (@$net_int_parsed_output){ >> >> my $lif_cnt++; >> >> print "lif of vserver >>> $n\n"; >> >> push >> (@{$lun_PR_resv_info->{'lun'}->{'vserver'}->{'fcp_lifs'}},$n); >> >> } >> >> >> >> print "lun PR resv related info>>>>>>>>>>>>>",Dumper >> $lun_PR_resv_info,"\n"; >> >> >> Thanks >> >> Sunita >> >> >> > > > -- > Regards, > Jitendra >