Hey there,
I am trying to get to grips with Hashes and they're causing me alot of problems.
I have the camel book, but it doesn't elaborate on how to populate a hash, other than hard coding it.
I want to populate a hash with key=>value pairs read in from a file (to an array) and split into pairs.
I am trying to loop through the array and populate the hash.
CODE:
for($i=2;$i<@indat;$i++) {
($key, $value) = (split '&', $indat[$i]);
$hash{$key} => $value;}
I have tried to use a temporary array to print the contents of the hash at this point, but it doesn't work.
Later in the program, I am trying to tie the values of an array (which are the same as the keys in the hash) to their value from the hash.
The reason for this is that the array is file names
(e.g.- abc.pdf), and the hash has these file names and also their titles. I want to create links to the files, but have the text of the link as the title of the file (from the hash).
CODE:
foreach $cuz(@cfiles) {
print "<tr><td><a href='$relcurfile$cuz' target='_blank'>$hash{'$cuz'}</a></td></tr>";}
but again this doesn't work.
I think I getting the problem at the populating stage, but I can't find any decent info on hash population on the fly.
Any help or pointers to info on the web would be really helpful.
Thanks
Jez

I am trying to get to grips with Hashes and they're causing me alot of problems.
I have the camel book, but it doesn't elaborate on how to populate a hash, other than hard coding it.
I want to populate a hash with key=>value pairs read in from a file (to an array) and split into pairs.
I am trying to loop through the array and populate the hash.
CODE:
for($i=2;$i<@indat;$i++) {
($key, $value) = (split '&', $indat[$i]);
$hash{$key} => $value;}
I have tried to use a temporary array to print the contents of the hash at this point, but it doesn't work.
Later in the program, I am trying to tie the values of an array (which are the same as the keys in the hash) to their value from the hash.
The reason for this is that the array is file names
(e.g.- abc.pdf), and the hash has these file names and also their titles. I want to create links to the files, but have the text of the link as the title of the file (from the hash).
CODE:
foreach $cuz(@cfiles) {
print "<tr><td><a href='$relcurfile$cuz' target='_blank'>$hash{'$cuz'}</a></td></tr>";}
but again this doesn't work.
I think I getting the problem at the populating stage, but I can't find any decent info on hash population on the fly.
Any help or pointers to info on the web would be really helpful.
Thanks
Jez
