in reply to Adding hash values together

In general Perl has a philosophy of "Do what I mean" (DWIM). In the context of numbers and strings Perl converts numbers to strings in a string context and converts strings to numbers in a number context.

What determines the context?

  • Hash keys are strings so are a string context
  • Hash values are either
  • arithmetic operators provide a number context
  • string operators (., cmp, eq, gt ...) provide a string context

    You can force a number context by using +0 and string by .'' (empty quoted string):

    my $NumericValue = "10" + 0; my $StringValue = 10 . '';

    Perl is Huffman encoded by design.