Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to compare the elements in an array of hashes and keep only the most recent item
    text
    copied!<p>I am using the the below Array of Hashes and would like to only display the most recent hash based off the 'Datetime', if four certain parameters are the same. Let me provide an example using the code below...</p> <p>If 'toy, kind, Stage, Step' are the same, then I would only like to store only that hash into a new array of hashes. </p> <p>Original Array of Hashes</p> <pre><code>$VAR1 = [ { 'Color' =&gt; 'green', '2nd Color' =&gt; 'blue', '3rd Color' =&gt; 'yellow', 'toy' =&gt; 'truck', 'toy_type' =&gt; 'ford', 'kind' =&gt; '4door', 'Stage' =&gt; 'Production', 'Step' =&gt; 'Platform', 'Datetime' =&gt; '2012/06/08 01:49:19' }, { 'Color' =&gt; 'red', '2nd Color' =&gt; 'green', '3rd Color' =&gt; 'yellow', 'toy' =&gt; 'truck', 'toy_type' =&gt; 'ford', 'kind' =&gt; '4door', 'Stage' =&gt; 'Production', 'Step' =&gt; 'Platform', 'Datetime' =&gt; '2012/06/08 01:46:17' }, { 'Color' =&gt; 'red', '2nd Color' =&gt; 'blue', '3rd Color' =&gt; 'green', 'toy' =&gt; 'truck', 'toy_type' =&gt; 'chevy', 'kind' =&gt; '4door', 'Stage' =&gt; 'Production', 'Step' =&gt; 'Platform', 'Datetime' =&gt; '2012/06/08 01:52:14' }, { 'Color' =&gt; 'red', '2nd Color' =&gt; 'blue', '3rd Color' =&gt; 'yellow', 'toy' =&gt; 'truck', 'toy_type' =&gt; 'chevy', 'kind' =&gt; '4door', 'Stage' =&gt; 'Production', 'Step' =&gt; 'Platform', 'Datetime' =&gt; '2012/06/08 01:24:14' }, { 'Color' =&gt; 'white', '2nd Color' =&gt; 'blue', '3rd Color' =&gt; 'yellow', 'toy' =&gt; 'truck', 'toy_type' =&gt; 'gmc', 'kind' =&gt; '4door', 'Stage' =&gt; 'Production', 'Step' =&gt; 'Platform', 'Datetime' =&gt; '2012/06/08 06:24:14' }, </code></pre> <p>New Array of Hashes I want saved to a variable:</p> <pre><code>$VAR2 = [ { 'Color' =&gt; 'green', '2nd Color' =&gt; 'blue', '3rd Color' =&gt; 'yellow', 'toy' =&gt; 'truck', 'toy_type' =&gt; 'ford', 'kind' =&gt; '4door', 'Stage' =&gt; 'Production', 'Step' =&gt; 'Platform', 'Datetime' =&gt; '2012/06/08 01:49:19' }, { 'Color' =&gt; 'red', '2nd Color' =&gt; 'blue', '3rd Color' =&gt; 'green', 'toy' =&gt; 'truck', 'toy_type' =&gt; 'chevy', 'kind' =&gt; '4door', 'Stage' =&gt; 'Production', 'Step' =&gt; 'Platform', 'Datetime' =&gt; '2012/06/08 01:52:14' }, { 'Color' =&gt; 'white', '2nd Color' =&gt; 'blue', '3rd Color' =&gt; 'yellow', 'toy' =&gt; 'truck', 'toy_type' =&gt; 'gmc', 'kind' =&gt; '4door', 'Stage' =&gt; 'Production', 'Step' =&gt; 'Platform', 'Datetime' =&gt; '2012/06/08 06:24:14' }, </code></pre> <p>Notice how I only wanted the most recent ford and recent chevy to be stored, but because there was only one gmc, I also wanted that stored.</p> <p>I was referring to the perldsc (http://perldoc.perl.org/perldsc.html) documentation, but it did not go into this great of detail. Is this even possible?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload