O'Reilly logo

Open Source Web Development with LAMP: Using Linux, Apache, MySQL, Perl, and PHP by Brent Ware, James Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required