I know this might sound a bit off the wall but there is a method to my madness. What I'm trying to do is put 2 variables together, one being a hash key and a number from a for loop inside the brackets...i.e. $hash{'$a'}. As is obvious the keys are numbers.
This brings up another question...is it possible to count the number of keys in a hash?
Basically what I'm trying to do is create a new hash in a new txt file using input from a form, or, if no input is in the form use the value from an existing hash. Form inputs listed as "input1, input2, etc.,. Like using a form to make it easier for a user to create a language file in a different language by reading the existing file and entering the info for the new file in the form.
Something like(not yet tried due to the variable issue)
tie (%hash, "DB_File", $dbfile) or die "Can't open $dbfile: $!\n"; %hash = ( for($b=0;$b<$cnt;$b++){$a=$b+1; #$cnt being the number of keys in the +hash $new"."$a="new_input_from_form"."$a";#. form is in a .pl file if($new"."$a ne ""){$new_key_and_value="'$a' => '$new"."$a',";} #use v +alue from the form in the hash elsif($new"."$a eq ""){$new_key_and_value="'$a' => '$hash{'$a'}',";} # +use the old value from the existing hash $new_key_and_value }#close the for loop ); #close the hash untie %hash
In reply to Double Variables by typomaniac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |