rick has asked for the wisdom of the Perl Monks concerning the following question:

I need to transfer a form text field to a %user_input% value. However, I am receiving error "% % are invalid characters."

At this stage, I am manually typing in predetermined "users.html" into the code:
<br><br><My:File name="manuallytyped.html">without using the %% variables.

I need a method so that the user is allowed to type in their own page names "users_input" field - ex: "Link1.html" can replace

<My:File name="<b>%user_input%</b>">

Note: Changes made to no avail:
foreach (split(m!</Genesis:File>!si, $template)) { next unless (m!<Genesis:File name=\"(.*?)\">(.*)!si); my ($file) = ($1); # print "\t" x 3, '<li>'; if (-e $file) { # print qq!<a href="$STATE{'web_path'}$file">$file</a> +- $str[152]!; } elsif ($file =~ m!\%!) { # print "$file - $str[151]"; } else { print $file; } # print "</li>\n"; } print "\t\t</ul>\n"; last Err; } return $err; }

This does not work:
foreach (split(m!</Genesis:File>!si, $text)) { next unless (m!<Genesis:File name=\"(.*?)\">(.*)!si); my ($file, $text) = ($1, $2); # strip leading and trailing vertical whitespace $text =~ s!^(\015|\012)*!!s; $text =~ s!(\015|\012)*$!!s; my $is_cgi = 0; ($temp_err_msg, $is_cgi) = &CheckName( $file,1 ); if ($temp_err_msg) { push(@temp_errors, $temp_err_msg); next; }

Replies are listed 'Best First'.
Re: passing user form input value to %placeholder%
by Tanktalus (Canon) on Apr 25, 2006 at 00:58 UTC

    Just out of curiosity ... why are you doing this rather than using an existing templating mechanism, such as HTML::Template or Template?

    If it's because you're using XML, then I would suggest using XML::Twig to parse it, and using its XPath-like language to find attributes with %'s in it, and then you can update those. Or I'd use one of the above template modules to create the XML from the template.

      This is a Perl script that allows web page creation. I needed to use Perl because its flexibility for administrative purposes. I took a long look at what I was actually trying to do and changed:

      $text =~ s!^(\015|\012)*!!s;

      to this:

          $text =~ s!^(%%(.*?)%%)*!!s;

      Thank you for your response. I will definately keep your suggestions in mind for my next project.