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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |