Even if you have a carriage return at the end of the string, several of the expressions should work, as shown in this session under the debugger:

DB<14> $volt = "0.940V\n" DB<15> print "matched\n" if $volt =~ /^0\.9[0-4]+V$/ matched DB<16> print "matched\n" if $volt =~ /94/ matched DB<17> chomp $volt DB<18> print "matched\n" if $volt eq "0.940V"; matched

You should really try with just one value and print the value with special characters that will show if your values contain something more than you think (leading space, trailing space, carriage return, whatever:

print ">$voltages[0]<\n"; # should print : >0.940V<

It might also turn out that you will not print anything, for example because you made a mistake on the array name, so that nothing will ever match because the array your are testing is simply empty, or whatever.

Finally, as already said, you should rather use the eq operator rather than the == operator for strings such as 0.940V (even though == will work by removing the trailing letter, for example 0.940V == 0.940 will return true).


In reply to Re: Trouble matching string with decimals by Laurent_R
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.