in reply to numeric hash keys

Read the error message again: You are passing the string "parent mass" to int, that's the source of the error message.

Hash keys are always stringified, but like any string Perl will automatically convert it back to a number if used in a numeric context (if it can).

Replies are listed 'Best First'.
Re^2: numeric hash keys
by AWallBuilder (Beadle) on Mar 06, 2015 at 13:55 UTC
    sorry I added the int($PM) to try and fix the problem but it didn't work. I get the same error without the int($PM) line. if I use <= in the if statement then why doesn't it treat the keys like a number?

      Please re-read our replies.

      When you use a value in numeric context, for example by using the <= operator on it, Perl expects a number. But you are handing it something else. Perl even tells you what it saw instead, but you seem to hide that value from us.

      Find out what the offending value is and then look at your code and think about how that value gets there.

      Most likely, printing $PM and thinking long and hard about the difference between what you expect in $PM and what you get might give you a hint.

      I get the same error without the int($PM) line.

      No, you don't - the error message will be different. Please provide the exact error messages and the exact code used to produce them.

      You've also edited your original post without marking it updated. Don't do that, see here for why.

      why doesn't it treat the keys like a number?

      If $PM is "parent mass", how do you expect Perl to use that as a number?

      I suspect your problem is in the input data.

      Please read and follow How do I post a question effectively? - please show the exact code used, the exact error message, and the exact sample input used to generate that error.