Hi Monks!
I have a big form that gets input from users, and another form gets populated from the inputs of this form. I am using a while loop to substitute the values and to generate another form. Since this form is big and sometimes not all the values will be filled in by the user, I decided to write in the while loop the code like this:
open (MYTEMPLATE, "${curr_dir}$file") || die "could not open templ
+ate $file: $!";
while (<MYTEMPLATE>) {
$_=~s/<\?--name_1-->/$name_1/g if defined $name_1;
$_=~s/<\?--name_2-->/$name_2/g if defined $name_2;
$_=~s/<\?--name_3-->/$name_3/g if defined $name_3;
$_=~s/<\?--name_4-->/$name_4/g if defined $name_4;
$_=~s/<\?--name_5-->/$name_5/g if defined $name_5;
$_=~s/<\?--name_6-->/$name_6/g if defined $name_6;
....
}
close MYTEMPLATE;
#variable names are here for showing code only
My theory is that by using "defined" the while loop would process faster and it also would save me with some warnings messages on my log file as well. Am I correct? Is this OK?
Thanks!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.