11.5. Inline Perl Sections

There are several different ways to embed Perl code into the Mason pages: <% ... %> sections, “%” lines, and <%perl> ... </%perl> blocks. The next sections explore these.

11.5.1. The <% ... %> Tag

These tags are useful for generating the values of variables and complex expressions. This example code generates HTML using these tags:

Name: <% $name %> 
Age:  <% $age %> 
Address: <% %address %> 
Price : <% $price*(1+$tax)%> 

The HTML generated is the result of the evaluation of the variables within the tags, including the evaluation of the final arithmetic expression.

11.5.2. % Lines

This type of Perl code is most useful for creating global variables and for embedding conditional and looping constructs.

Put this example ...

Get Open Source Web Development with LAMP: Using Linux, Apache, MySQL, Perl, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.