in reply to Double Variables

You'd be much better off telling us about the big picture, showing us a little of your input data and showing us what you want the output to look like. Aside from anything else, you don't really store a hash in a file, although you may store the data contained in a hash in a file. But if you are trying to do that you would probably be better off using either YAML or a database (DBD::SQLite perhaps).

True laziness is hard work

Replies are listed 'Best First'.
Re^2: Double Variables
by typomaniac (Novice) on Jun 25, 2011 at 03:38 UTC

    I'm putting together a "prototype" script of what I'm trying to accomplish and will post it in a few days. You mentioned about not storing a hash in a file. In the .txt file the info is as follows:

    my %hash={ 'key1' => 'value1', 'key2' => 'value2', )

    When the hash is tied I call the values like:

    print"The first value is $hash{'key1'}.";

    How should I go about this? I have so much to learn about perl and spend hours trying to figure things out.

      Don't worry about a prototype script as a way of showing us what you are trying to do. Instead describe in words what the project is about. If you show us code without giving us the background we can criticise the code for you, but we can't help with finding a good solution for the project. So far it looks like you have latched on to a solution for a small part of the project, but in fact could probably make better use of some higher level direction.

      True laziness is hard work

        The project I'm attempting is to make it easy for a user to convert a language file from one language to another using a form while saving the file being translated. In the case the original file is English and if someone wants to use the script in a different language--in this case Tagalog as I'm currently in the Philippines but also to be used in China eventually.
        All pages opened will be in the language designated in a settings file (db). The first page of the script will contain a short form where an interpreter can choose from the language files in place via a <select> input as follows:

        print"Please Select A Language To Convert\n" print"<select name="lang_files_completed">\n"; print"<option value="$lang_files{'1'}">$lang_files{'1'}</option>\n";#l +ist all files already written print"</select>\n"; print"<br />Enter The Name Of The New Language\n"; print"<input type="text"name="new_language">\n"

        Submitting this form will put in place another form with all the entries in the language file selected with a textbox under it to type in the new language:

        print"$lng{'1'}\n"; print"<input type="text"name="new_language_text">\n";

        When this form is submitted the new file will be created and also added to the <select> input for future translations.

        I still have much to figure out such as how to call the values from the text file which holds them without entereing a hash into that file. One of the things I am considering at this point(thought I had it all figured out) was just creating the files to process the forms as I go. That was where I came up with the idea of using a forloop and just using numbers for the keys. Once the number of entries in the db are counted my intention was creating the file on the fly(please excuse using $a and $b for variables---for simplicity sake).

        for($b=0;$b<$cnt;$b++){$a=$b+1;###$cnt---is number of entries in the h +ash print AAA"print\"\$lng{\'$a\'}<br />\\n\"\;\n"; print AAA"print\"<input type=\\\"text\\\"name=\\\"nl$a\\\"size=\\\"200 +\\\"><br />\\n\"\;\n"; }

        My thinking was since the keys are numbers I would just use the forloop and creating the file on the fly this way prints out like $nl1, $nl2, etc.,... Please overlook things if I'm out of line doing it this way but with what little I know about perl at this point I'm just trying to make ends meet. I have other things to get squared away on also I realize. If you would like I will still post the code for the project. I've learned most from online tutorials, forums, etc.,. If budget allowed for it I would stock up on perl books(I do have a 11 year old copy of the Perl Cookbook which has also helped from what I've been able to understand of it. I see a bunch of tutorials at this site I intend to feast on. I hope I was able to explain the nature of the project clear enough. Thanx. Dave