<?xml version="1.0" encoding="windows-1252"?>
<node id="1008475" title="Re: How can one call the lowest value of an array by reference?" created="2012-12-12 05:05:13" updated="2012-12-12 05:05:13">
<type id="11">
note</type>
<author id="461912">
GrandFather</author>
<data>
<field name="doctext">
&lt;p&gt;Trying to maintain parallel arrays in that fashion if fraught with peril. Instead use a data structure where you can treat each data pair as an entity. One way to do that would be to use OO and generate an object for each animal. For the current sample a simple hash will suffice. Consider:&lt;/p&gt;
&lt;c&gt;
use strict;
use warnings;

my %animals = (
    Cat =&gt; 5,
    Bat =&gt; 3,
    Cow =&gt; 2,
    Dog =&gt; 12,
    Rat =&gt; 2
);
my %byValue;

push @{$byValue{$animals{$_}}}, $_ for keys %animals;

my @ordered = sort {$a &lt;=&gt; $b} keys %byValue;

print "$_: @{$byValue{$_}}\n" for @ordered;
&lt;/c&gt;
&lt;p&gt;Prints:&lt;/p&gt;
&lt;c&gt;
2: Rat Cow
3: Bat
5: Cat
12: Dog
&lt;/c&gt;
&lt;p&gt;Note the use of the reverse lookup hash byValue to ease accessing the animals in sorted order.&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-461912"&gt;
True laziness is hard work
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1008463</field>
<field name="parent_node">
1008463</field>
</data>
</node>
