Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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:

use strict; use warnings; my %animals = ( Cat => 5, Bat => 3, Cow => 2, Dog => 12, Rat => 2 ); my %byValue; push @{$byValue{$animals{$_}}}, $_ for keys %animals; my @ordered = sort {$a <=> $b} keys %byValue; print "$_: @{$byValue{$_}}\n" for @ordered;


2: Rat Cow 3: Bat 5: Cat 12: Dog

Note the use of the reverse lookup hash byValue to ease accessing the animals in sorted order.

True laziness is hard work

In reply to Re: How can one call the lowest value of an array by reference? by GrandFather
in thread How can one call the lowest value of an array by reference? by supriyoch_2008

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (7)
    As of 2015-03-28 02:38 GMT
    Find Nodes?
      Voting Booth?

      When putting a smiley right before a closing parenthesis, do you:

      Results (621 votes), past polls