in reply to foreach and if inside <<ENDHTML? Can they work?

Your goal from all this code + HTML seems to be templated HTML, complete with if-logic and loops. I have a feeling that if you just take a glance at HTML::Template, you will quickly realize how much time and agony it can save you. In short, it does simple variable substition as well as, you guessed it, if-logic and loops! If you search the monastery, you'll find just loads of resources, not the least of which is HTML::Template Tutorial.

(Of course, there are other good templating systems out there, but HTML::Template covers exactly the functionality it appears you are looking for, so I think it's the best choice for you)

As your code stands at the moment, you seem to rate a #3 on Cody Pendant's scale of Perl/HTML interaction, which isn't bad. You could certainly do much worse! However, you've stumbled upon one of the main limitations of here-docs. So although I don't really address your original question (the other posts cover that pretty well), I just wanted to save you the trouble of trying to make your own templating system (#4 on the scale), which is a common next step up the ladder, but nearly always given up later in favor of a proven templating system (#5).

blokhead

  • Comment on Re: foreach and if inside <<ENDHTML? Can they work?

Replies are listed 'Best First'.
Re: Re: foreach and if inside <<ENDHTML? Can they work?
by frogboy (Initiate) on Aug 13, 2003 at 06:29 UTC
    Heres a link to the html that links to the post.cgi You can feel out the form and hit submit if you want to see what i am working with. I am on a tripod server and i can only use the pm that they previde. See my problem!
      HTML::Template is a pure Perl module, so you can just upload the .pm file and require it from your script.

      blokhead

      Thanks guys for the help. This is my finally script please tell me what you think. It sends it another script that thn emails me using my mail porgram in tripod the tripodmail.pm Feel free to check out the script at HERE If you check it out and find a problem please tell me.
      #!/usr/bin/perl require TripodMail; print "Content-type:text/html\n\n"; $FORM{'GraphicsDesign'} = ""; $FORM{'Screenprinting'} = ""; $FORM{'Digitizing'} = ""; $FORM{'Embroidery'} = ""; $FORM{'Manufacturing'} = ""; $alpha = ""; $printy_stuff = ""; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value;} if ($FORM{'services'} eq "yes") { $printy_stuff = qq( Services:<br> $FORM{'GraphicsDesign'}<br> $FORM{'Screenprinting'}<br> $FORM{'Digitizing'}<br> $FORM{'Embroidery'}<br> $FORM{'Manufacturing'}<br>); } if ($FORM{'textarea'} ne "") { $alpha = "Coments: $FORM{'textarea'}"; } print <<EndHTML; <html><head><title>Order Form</title></head> <body> <h1>Please check your order.</h1> If all the info is correct please click yes, if not click the back but +ton on your browser. <p></p>$FORM{'firstname'} $FORM{'lastname'}<br> Email: $FORM{'email'}<br> Phone Number: $FORM{'number'}<br> <br>Catalog: $FORM{'catalog'}<br> Brand: $FORM{'brand'}<br> Item number: $FORM{'inumber'}<br> Color: $FORM{'color'}<br> Sizes: $FORM{'size'}<br><br> $printy_stuff<BR> $alpha <form method="post" action="post.cgi"> <input type="hidden" name="firstname" value="$FORM{'firstname'}"> <input type="hidden" name="inumber" value="$FORM{'inumber'}"> <input type="hidden" name="number" value="$FORM{'number'}"> <input type="hidden" name="catalog" value="$FORM{'catalog'}"> <input type="hidden" name="Embroidery" value="$FORM{'Embroidery'}"> <input type="hidden" name="brand" value="$FORM{'brand'}"> <input type="hidden" name="lastname" value="$FORM{'lastname'}"> <input type="hidden" name="Screenprinting" value="$FORM{'Screenprintin +g'}"> <input type="hidden" name="size" value="$FORM{'size'}"> <input type="hidden" name="email" value="$FORM{'email'}"> <input type="hidden" name="color" value="$FORM{'color'}"> <input type="hidden" name="Digitizing" value="$FORM{'Digitizing'}"> <input type="hidden" name="GraphicsDesign" value="$FORM{'GraphicsDesig +n'}"> <input type="hidden" name="services" value="$FORM{'services'}"> <input type="hidden" name="Manufacturing" value="$FORM{'Manufacturing' +}"> <input type="hidden" name="button" value="submit"> <input type="hidden" name="textarea" value="$FORM{'textarea'}"> <input type="submit" name="button" value=" yes "> </form> EndHTML print "</body></html>\n";