in reply to Detecting a Null or Enter key

From a quick scan, if the user presses the <enter> key, s?he will enter a newline ("\n"), which Perl will interpret as 0 in the numerical equality test, and 0 is less than 1.0, so the result for the first part of condition 3 is "TRUE." The second part of the test for condition 3 is ill-formed, in that "Cust1"||"Cust2" is legitimate, albeit useless, Perl, which will return true if "Cust1" or "Cust2" is true, which they are given Perl's notion of truth. You should probably rewrite that part of the test to

$bak_id eq 'Cust1' or $bak_id eq 'Cust2'
or use a regex:

$bak_id =~ /^Cust[12]$/
in both places it occurs. Actually, since you're using the same sort of test twice, I'd move the logic into a named sub against the inevitable day when the customer (instructor?) generalizes Cust[12] to /Cust[0-9]+/.

Since this test is before the tests to return to main menu, it never gets there.


Addendum There are many ways to code the logic you need to validate input, including some modules. My general preference, in Perl, is to assume all inputs from stdin are strings, and postpone any numerical tests until after I've ensured myself that the data actually represent legitimate numbers.


Information about American English usage here and here. Floating point issues? Please read this before posting. — emc