I don't think you need to loop or grep.

Assuming that the values you are looking up are always in the hash, then you can use the array directly in a hash slice to produce the new array of the values like this

my %hash; @hash{ qw[-0.9940000000 0.1190000000 -0.0355000000] } = qw[ -0.993999999999999999 -0.118999999999999999 -0.035499999999999 +999 ]; print Dumper \%hash; $VAR1 = { '0.1190000000' => '-0.118999999999999999', '-0.9940000000' => '-0.993999999999999999', '-0.0355000000' => '-0.035499999999999999' }; my @array = qw[ 0.1190000000 -0.0355000000]; my @new = @hash{ @array }; print @new; -0.118999999999999999 -0.035499999999999999

The caveat is that if any of the values in @array don't exist in the hash as keys, then you will get undef in the corresponding elements of @new.

However, this may actually be useful as it will give you a way of detecting that you had values in @array that didn't exist as keys in %hash.

All of that said, if your ultimate goal is to compare floating point numbers with a fugde factor for floating point representation inaccuracies, then there are probably better, numerical ways of doing this, but you would need to show us how you are using this to be sure. I'm a bit thrown by your hash associating +0.1190000000 with -0.118999999999999999 ?? Or is that a typo?


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller



In reply to Re: Re: Re: hashes - finding values by BrowserUk
in thread hashes - finding values by Anonymous Monk

Title:
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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.