belize has asked for the wisdom of the Perl Monks concerning the following question:
I am submitting a form that will replace matching fields in a template file with what was submitted.
The template file takes this form:
LABEL1: [field1] LABEL2: [field2] LABEL3: [field3]
I open the template file, read each line into an array, then start working on each line as follows:
foreach $File (@File) { $File =~ s/\n//; foreach $Field (@InputFields) { $ReplaceVar = $FORM($Field); $SearchVar = '\[' . Field . '\]'; $File =~ s/$SearchVar/$ReplaceVar/g; } print "$File\n"; }
QUESTIONS:
1. If someone does not fill Field1 in the form, the printout will show " LABEL: [Field1] ". How do I get rid of this. Do I first run the above, then run it again searching " '\[.*\]' " and replacing it with ""? I tried this but running it a second time erased all the fields.
2. What does " $File =~ s/\n//; " accomplish?
Thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Pattern Match and Replace Problem
by Chady (Priest) on Apr 27, 2001 at 23:51 UTC | |
Re: Pattern Match and Replace Problem
by belize (Deacon) on Apr 27, 2001 at 23:50 UTC | |
by Chady (Priest) on Apr 27, 2001 at 23:56 UTC | |
Re: Pattern Match and Replace Problem
by little (Curate) on Apr 27, 2001 at 23:32 UTC | |
by belize (Deacon) on Apr 27, 2001 at 23:39 UTC |
Back to
Seekers of Perl Wisdom