in reply to $var{el} += 1 vs $var{el} = $var{el} + 1

Note that if you dereference the same keys several times, it might save you some runtime (not talking about readability) by createin variables for them:
my $location = $mainHash->{$hashType}{$regionID}{MetricType}{$resultHa +sh->{Location}}; $location->{$yearMonthDateList[$start]} += $resultHash->{Value};
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: $var{el} += 1 vs $var{el} = $var{el} + 1
by banesong (Acolyte) on Aug 13, 2013 at 14:44 UTC

    Okay, so that begs a question - what is the impact on performance between:

    $totalsHash{$resultHash{SomeKey}} = $resultHash{SomeKey}{AltValue};

    vice

    my $resultKey = $resultHash{SomeKey}; $totalsHash{$resultKey} = $resultHash{$resultKey}{AltValue};

    This is assuming I am referring to the SomeKey value multiple times. I would assume the second scenario is more efficient.

      It depends on the number of invocations. Use Benchmark to check.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Okay, so that begs a question - what is the impact on performance between:

      irrelevant :)

      Throwing memory at the problem (extra $scalar) is slightly faster than extra (double-1) hash lookups

      But you meant to type

      $someKey = $resultHash{SomeKey}; $totalsHash{ $someKey } = $$someKey{AltValue};