if( $voltages[$count] == "0.940V" )           {  #  Did not work

Are you reading @voltages from a file, by any chance? If so, you probably have newlines at the end of each string. Use chomp to get rid of them.

It's also helpful to print out the value to make sure it is what you think it is:

print "<$voltages[$count]>\n";

If you have trailing space or newlines or anything, it will become quite obvious.

Update: A couple of additional thoughts

Instead of ==, use eq, to do a string comparison, even though Perl will numify both arguments.

Do you really just need to find all @voltages that match, exactly, "0.940V"? If so, the simple eq will suffice. If not, the regexp /^(\d+\.\d+)V$/ will match any non-negative floating point voltage, with the number (but not the "V") in $1 if it matched.

Finally, going through the array by number looks a little suspect to me in this case; can you tell us more about what your "processing" entails? There may be a more elegant solution to what you're trying to achieve.


In reply to Re: Trouble matching string with decimals by rjt
in thread Trouble matching string with decimals by deshdaaz

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.