in reply to multidimenional hashes

This is a case when you have to use "", because you are using formatted numbers, that must be kept as strings.

$fval{"$flat[$i]"}{"$flong[$i]"}

Replies are listed 'Best First'.
Re: Re: multidimenional hashes
by hmerrill (Friar) on Oct 11, 2002 at 13:45 UTC
    fglock, and the others, are correct. Here is my version of your last 3 print statements:
    print qq|testing: $flat[1], $flong[1]\n|; print qq|testing: $fval{"39.750000"}{"-179.000000"}\n|; print qq|testing: $fval{"$flat[1]"}{"$flong[1]"}\n|;
    The "qq" operator lets you use whatever you want to use as the delimiter of the string - I chose to use the pipe(|) since the string itself contains double quotes, *and* my other favoite choice for qq operator, {}. HTH.
Re: Re: multidimenional hashes
by Anonymous Monk on Oct 11, 2002 at 12:59 UTC
    Thanks. But does that mean that I have no way of referencing a hash value by giving an "index + offset"? For example, I want to be able to say things like
    $fval{$flat[$i]+0.25}{$flong[$i]}
      You can, you just have to format the value:
      $fval{sprintf('%3.6f', $flat[$i]+0.25)}{$flong[$i]}

      Maybe you'd better be sure that your keys are are not formatted numbers:

      $fval{$flat[$i]+0}{$flong[$i]+0}
        Yes! Thank you. (but, i still don't see what went wrong in my original example, since I "replicated" the string that was being stored in the variable, and yet still the hash value was undefined.)