First of all, what you are doing is
Cargo Cult programming. Granted, a lot of us started that way, and some of us fall into that trap each time we meet an unfamiliar language/system/environment, but it leads to high blood pressure and hair loss. You should first try to understand WHY something is written the way it is, and only then try to write your own.
I don't know where you picked the "supposedly standard format", but it wouldn't run in any JavaScript I ever came across. I don't even see the purpose of doing it that way: after all, if you want to display a form with empty fields, just print it that way.
But in the hope that it might do some good to you and others who might run across this article, let me write something about setting fields in HTML forms in general.
There are several options:
- You can hardcode your values into your HTML file (<input type=text name=whatever value="hello world!">), and simply send that to the browser with a single print statement.
- You can laboriously construct the form inside your CGI script, either by using <<here documents, or by using CGI.pm's HTML element routines (print textfield(-name=>'whatever' -default=>'hello world!');
- You can use a templating tool, such as HTML::Template, let a designer design the HTML, and then change each input field to have something like this:<input type=text name=whatever value="<TMPL_VAR name="whatever">">. Once you've done that, you can set all the values from your script very quickly.
- Or (recommended for applications you're likely to come accross in the near future), you could use HTML::FillInForm, which parses the HTML on the fly, and then lets you assign all the values very quickly and conveniently.
None of that options can be said to be
Best option for all occasions. Each option involves compromises. The easier it is to implement, the slower it will likely be once it is deployed. But even HTML::FillInForm, which parses the HTML each time it displays it, is plenty fast for most applications.
And hopefully, by the time you graduate to writing scripts that need to run on a hundred-requests-per-second production server, you will have developed a feeling of when programmer convenience needs to be sacrificed to the goods of speed, and when programmer's time is better spent doing other things.