Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Embeding Perl in HTML the PHP way

by aaron_baugher (Curate)
on Sep 11, 2012 at 22:33 UTC ( #993077=note: print w/replies, xml ) Need Help??

in reply to Embeding Perl in HTML the PHP way

Your example is how it's done in HTML::Mason, although the syntax would be slightly different. For one thing, you don't need the printf at all, since you're just printing a string. So you can do any of these:

<body> <% $some_string %> </body> <body> % print $some_string; </body> <body> <%perl> print $some_string; </%perl>

Like others here, I prefer frameworks these days. Mixing code with layout just doesn't scale well at all. Mason is better than PHP because it's Perl, but things still get ugly easily for some of the same reasons they do in PHP. Currently I'm using Dancer with Dancer::Template::Mason as my templating system, and liking that quite a bit. My templates are Mason, so they can use Perl code for things like loops, rather than requiring me to learn some new templating system's loop syntax. But since all my actual code that processes the data (Controller and Model, in MVC terms) is separate, the template files are still very clean.

Aaron B.
Available for small or large Perl jobs; see my home node.

Replies are listed 'Best First'.
Re^2: Embeding Perl in HTML the PHP way
by sundialsvc4 (Abbot) on Sep 12, 2012 at 00:14 UTC

    Yes, I think that everybody figured out pretty-quickly that the inline-code approach was an inferior approach ... particularly when I18N (internationalization) began to be a very big deal in this world-wide web of ours.   Really good templating systems, and then, really good web frameworks built on them, appeared in most language systems and all of them have matured along generally similar lines.   There is no reason to “go back,” and an abundance of reasons not to.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993077]
[TCLion]: Good Morning Monks, I am parsing logs and some date time formats are inconsistent. I am trying to make output all same format. What is the best way to convert a month(word) to month(number)?
[Corion]: TCLion: I'm not aware of a better way than manually building the hash, as all strptime incarnations I know have nasty edge cases
[davido]: And remember; time is hard. :) As soon as you think, I've got this, you'll discover that time is harder than that. :)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2017-03-23 14:40 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (287 votes). Check out past polls.