Here is a way of doing this. Tested and commented. But, like Bob says, you
may well end up loosing track of what hashes you've created...
--- code ---
@indexNumbers = qw(1 2 3 4);
foreach $number(@indexNumbers) {
$hashname = "hash$number"; # Create a scalar with the name of the
hash you want
$$hashname{test} = $number; # Create the hash (hash1, hash2, etc)
and one key called test with a value of the current hash index. So
$hash1{value} should be 1, $hash2{value} should be 2 etc
}
# Now check the results
print "Hash1 OK\n" if defined %hash1;
print "Hash2 OK\n" if defined %hash2;
print "Hash3 OK\n" if defined %hash3;
print "Hash4 OK\n" if defined %hash4;
print "Hash5 OK\n" if defined %hash5; # This shouldn't and doesn't print as
we didn't create a hash5
# Just to make sure, check the value of the test key in a couple of the
hashes
print "This should be a value of 1 <$hash1{test}>\n";
print "This should be a value of 3 <$hash3{test}>\n";
--- code ---
John
-----Original Message-----
From: Elie De Brauwer [mailto:[EMAIL PROTECTED]]
Sent: 09 August 2001 13:43
To: [EMAIL PROTECTED]
Subject: Creating a hash from a name stored in a variable ...
I searched google, asked some people on irc but no-one could answer me.
$max_index is a value gotten from a database which contains the number of
entry's
for($i = 0, $i < $max_index, $i++){
%data$1{name} = #get the name from the database matching the index
and store
it here ...
}
This is very simplistic in not working code what i want to do. I want to
generate a hash variable name. %data1, %data2 .... where the numbers are
read
from a variable .... How can i do this ?
--
<======================>
real men do it in perl ;)
De Brauwer Elie
[EMAIL PROTECTED]
<======================>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------Confidentiality--------------------------.
This E-mail is confidential. It should not be read, copied, disclosed or
used by any person other than the intended recipient. Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful. If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]