Aaron DeLoach said:
I would like the key to be the hash name being extracted from the test file.
I think it's time you showed us a sample of the input lines (those that
are given to eval() to produce a hash).
I guess my question should have been phrased differently. It doesn't matter
where the hashes are coming from. The problem now verified was the fact that
a key name was needed.
Indeed. It's the key we're talking about. You need one, and in all
likelihood it will be extracted from the line that generates the key.
What I wanted to achieve was the ability to create a 'main hash'
*containing* other hashes or HoH's - where the name of the hash being
incorporated into the 'main' hash was the hash name itself. For example:
File contains:
%hash1.....
%HoH...
%hash2...
Are you saying the input file contains bits of code that assign hashes
to program variables? Again, show us a few examples.
If that is the case, the code in the input file is really part of the
source code and shouldn't be executed piece-wise through eval. You
should re-thing the design.
ONE "Main" hash built from file:
%Main=(%hash1...%HoH...%hash2...);
A hash isn't a sequence of other things, as "(%hash1...%HoH...%hash2...)"
would indicate. To store something in a hash you need a key, and to
retrieve something from a hash you also need a key. That you skip
the keys in your representation shows that you have no clear idea
of how a hash works.
As mentioned three or four replies back, you could build an array
of the resulting hashes:
@main = ( \ %hash1, \ %HoH, \ %hash2, ....);
The file containing the hashes is being built 'on the fly' by other
resources. I do not have prior knowledgs of how many, or the names thereof
the hashes inside.
That's the problem with variable names that are generated at run time.
You don't know what they are and cant access the data.
Instead of building code that assigns to a program variable, build
code that returns the hash without assigning it to a named variable.
Then you can eval it and assign the result to a known place.
With a function that would grep/eval/whatever the text file into a "main"
Now, "grep/eval/whatever" make strange bedfellows. Grep and eval aren't
alternatives to accomplish the same thing.
hash, I would be able to determine the names of the hashes incorporated by
looping through the outer keys.
You seem to hope the key names will magically appear once you have
the "main hash". It's the other way 'round. Before you can build
the main hash, you need a method to *assign* keys to each of the
partial hashes.
Anno