I have multiple values for each key in the hash. Here, I print the values of each key  print "$var:",join ',',@{$hash{$var}},"\n";   Output of the above print statement is:  ABC:1,2,3,1,4,2, DEF:9,3,4,5,3,5,   Now, I want to remove duplicates in the values. The desired output is,  ABC:1,2,3,4 DEF:9,3,4,5   Can someone help me in this?  Thanks
33672
I have an array in Perl:  my @my_array = ("one","two","three","two","three");   How do I remove the duplicates from the array?
63865
Since arrays and hashes can only contain scalars in Perl, why do you have to use the $ to tell the interpreter that the value is a scalar when accessing array or hash elements? In other words, assuming you have an array @myarray and a hash %myhash, why do you need to do:  $x = $myarray[1]; $y = $myhash{'foo'};   instead of just doing :  $x = myarray[1]; $y = myhash{'foo'};   Why are the above ambiguous?   Wouldn't it be illegal Perl code if it was anything but a $ in that place? For example, aren't all of the following illegal in Perl?  @var[0]; @var{'key'}; %var[0]; %var{'key'};
117983
I am trying to remove duplicate and creating a set and list with non duplicate values related to field ord__c . Trying to minimize the code as far as possible. Let me know if I can handle the same using the below piece of code I am using :   Set &lt; Id &gt; OrId = new Set &lt; Id &gt; ();  Integer j = 0;         while (j &lt; ListR.size())         {           OrId.add(ListR.get(j).Ord__c);           if(OrId.contains(ListR.get(j).Ord__c))           {             ListR.remove(j);           }           else           {             j++;           }         }
110365
I have a file contains around million number of lines. In the lines I have a field called transactionid, which has repetitive values. What I need to do is to count them distinctly.  No matter of how many times a value is repeated, it should be counted only once.
104858
Let's say I start with a particular 256 bit value. Call this $v$. I then hash that value, and get another 256 bit value. Call this $\text{SHA256}(v)$. I take this value and get another 256 bit value. Call this $\text{SHA256}^2(v)$. More generally, let's call the result of hashing $v$ repeatedly $n$ times $\text{SHA256}^n(v)$.  Now my question is, how big will $n$ be, such that $\text{SHA256}^n(v) = v$?  It would seem to me, that if it's a giant sort of permutation, $n$ would have to be $2^{256}$, is that correct? Is that provable, or is there any information on this? (Just curiosity, really.)  Another question I had was, do all 256 bit strings have unique SHA256 values, and is there a way to show that? (Or, stated differently, can it be shown that there are no SHA-256 collisions in the language of all "256 bit strings"?)
8585
Is there a built-in that removes duplicates from list in Python, whilst preserving order? I know that I can use a set to remove duplicates, but that destroys the original order. I also know that I can roll my own like this:  def uniq(input):   output = []   for x in input:     if x not in output:       output.append(x)   return output   (Thanks to  for that .)  But I'd like to avail myself of a built-in or a more Pythonic idiom if possible.  Related question:
91941
$ cat data.txt  aaaaaa aaaaaa cccccc aaaaaa aaaaaa bbbbbb $ cat data.txt | uniq aaaaaa cccccc aaaaaa bbbbbb $ cat data.txt | sort | uniq aaaaaa bbbbbb cccccc $   The result that I need is to display all the lines from the original file removing all the duplicates (not just the consecutive ones), while maintaining the original order of statements in the file.  Here, in this example, the result that I actually was looking for was  aaaaaa cccccc bbbbbb   How can I perform this generalized uniq operation in general?
7527
How do I select the unique elements from the list {0, 1, 2, 2, 2, 3, 4, 4, 5} so that I get {0, 1, 3, 5}, effectively removing all instances of the repeated elements {2, 4}?
1260
I am trying to print a simple value for $AR1_p1 but the variable $i is not evaluating. for i in 1 2 3 4 do     AR1_p1=22     AR1_p2=23     AR1_p3=24     AR1_p3=25     echo $AR1_p$i done   It's like concatenating dynamically. Any suggestions on how to fix this?.
93053
(assume php5) consider  &lt;?php      $foo = 'some words';      //case 1     print "these are $foo";      //case 2     print "these are {$foo}";      //case 3     print 'these are ' . $foo; ?&gt;   Is there much of a difference between 1 and 2?  If not, what about between 1/2 and 3?
2818
I know in JavaScript, objects double as hashes, but I have been unable to find a built-in function to get the keys: var h = {a:'b', c:'d'};  I want something like var k = h.keys() ; // k = ['a', 'c'];  It is simple to write a function myself to iterate over the items and add the keys to an array that I return, but is there a standard cleaner way to do that? I keep feeling it must be a simple built in function that I missed but I can't find it!
112023
In PHP, I can write:  $vname = 'phone'; $$vname = '555-1234'; print $phone;   ... And the script will output "555-1234".  Is there any equivalent in Perl?  Is there any way to constrain $phone to the scope of the local block, as if I'd written my $phone? Using my $$vname gives me "Can't declare scalar dereference in my at ..." errors.
9730
How can I remove duplicate values from an array in PHP?
60487
I have this input:  sdkxyosl 1 safkls 2 asdf--asdfasxy_asd 5 dkd8k  jasd 29 sdi44sw 43 asasd afsdfs 10 rklyasd 4   I need this output:  sdi44sw 43 dkd8k  jasd 29 asasd afsdfs 10 asdf--asdfasxy_asd 5 rklyasd 4 safkls 2 sdkxyosl 1   So i need to sort the lines by the last column.  I don't know how many columns are in one line.  I just can't figure it out, how to do it. I don't have "perl powers". I just have ~average scripting powers with sed, awk, cut, etc..   Does somebody know how to do it?
3020
How can I remove duplicate values from a multi-dimensional array in PHP?  Example array:  Array (     [0] =&gt; Array     (         [0] =&gt; abc         [1] =&gt; def     )      [1] =&gt; Array     (         [0] =&gt; ghi         [1] =&gt; jkl     )      [2] =&gt; Array     (         [0] =&gt; mno         [1] =&gt; pql     )      [3] =&gt; Array     (         [0] =&gt; abc         [1] =&gt; def     )      [4] =&gt; Array     (         [0] =&gt; ghi         [1] =&gt; jkl     )      [5] =&gt; Array     (         [0] =&gt; mno         [1] =&gt; pql     )  )
119081
I am trying to output the values of array element but I am getting weird output. Please have a look at it and help me solve it. Thank you.  n=2 declare -a myarray[$n] myarray[0]=hey myarray[1]=hello myarray[2]=bye for i in ${myarray[@]} do         echo $i done   Output:  robin@robin-VirtualBox:~/lx$ sh array.sh array.sh: 2: array.sh: declare: not found array.sh: 3: array.sh: myarray[0]=hey: not found array.sh: 4: array.sh: myarray[1]=hello: not found array.sh: 5: array.sh: myarray[2]=bye: not found array.sh: 6: array.sh: Bad substitution
80225
Evidently hash keys are compared in a case-sensitive manner.  $ perl -e '%hash = ( FOO =&gt; 1 ); printf "%s\n", ( exists $hash{foo} ) ? "Yes" : "No";' No  $ perl -e '%hash = ( FOO =&gt; 1 ); printf "%s\n", ( exists $hash{FOO} ) ? "Yes" : "No";' Yes   Is there a setting to change that for the current script?