[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-AnyPerl] Can Hash Keys Contain Variables?



I have a hash, %GM, and a counter variable, $cntGM (= 1, 2, etc.). I wish to
construct keys for this hash of the form:

Min$cntGM, Mean$cntGM, etc. (e.g., Min1, Min2, Max1, Max2, etc.)

I tried:

$GM{Min$cntGM} = <some value>;

since {} are supposed to act as double-quotes, and thus evaluate $cntGM.

However, when I run my script, I get the following error:

# Can't call method "Min" without a package or object reference, <INFILE>
chunk 3102.

I don't understand the error, but really just want to know if one can
generate keys of this form at run-time (i.e., without knowing a priori how
many keys are needed)?

I need to be able to account for a variable number of certain items in files
that are input to my script, and be able to write them to an output file in
an order that can only be determined at run-time.  Hashes seemed a much
better option than trying to key track of array indexes, etc.

Mark
----------------------
Mark J. Yannuzzi
myannuzzi@aya.yale.edu

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org