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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.