http://qs321.pair.com?node_id=1193216

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 (Canon) 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.