Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

using a 'here' doc to build a web page

by Anonymous Monk
on Jun 21, 2017 at 15:23 UTC ( #1193216=perlquestion: print w/replies, xml ) Need Help??

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

I am constructing a web page by first defining variables which are extrapolated in the 'HERE' document. I am creating a HTML file by printing the 'HERE' document. It seems to be working OK. Is this a valid approach?

Replies are listed 'Best First'.
Re: using a 'here' doc to build a web page
by hippo (Bishop) on Jun 21, 2017 at 15:35 UTC
    Is this a valid approach?

    It is valid but it won't be the most scalable or maintainable in the long term. If you have not already done so, do consider one of the excellent templating systems available on CPAN. While they might be considered overkill for a single, isolated web page the knowledge will stand you in good stead should you attempt more ambitious projects in future.

Re: using a 'here' doc to build a web page
by marto (Cardinal) on Jun 21, 2017 at 15:30 UTC

    What framework are you using? Mojolicious::Lite has a nice templating system by default (see this tutorial), other templating systems are optional, and a logical path for growth.

      not using a framework; hand-coding CSS and HTML. Mojolicious::Lite is something I will explore...thanks

        Are you using CGI? Even that will likely be better (safer) than something hand rolled. I'd suggest that you start off with Mojolicious::Lite, the documentation is great.

Re: using a 'here' doc to build a web page
by Discipulus (Abbot) on Jun 21, 2017 at 17:06 UTC
    > Is this a valid approach?

    as already said it will be valid for a small, not often changed project. But since Perl 5.26 at least you can indent your heredocs: see Indented_Here-documents in perldelta.

    A template system is something good to have in your bag of tools: recently in an interesting, similar thread Text::Xslate was suggested as terribly fast compared to the classical Template::Toolkit see Best way to start a perl project

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1193216]
Approved by marto
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2021-11-30 16:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?