10.7. Other Embperl Variables—$row and $col

Embperl can generate one- or two-dimensional tables dynamically with the use of $row and/or $col. If either $row or $col (or $cnt) is used within a <table>, Embperl repeats the text between <table> and </table> as long as the expression that includes $row/$col does not evaluate to undef.

For instance, if a program has this code:

[- @nums = (1..5); -] 
<table> 
  <tr><td>[+ $nums[$row] +]</td></tr> 
</table> 

this means start the table and then use $row to loop through @nums, one element at a time. And because it is $row, each element is treated as a row, so it repeats <tr><td> ... </td></tr>. Therefore, this is the result of this code:

 <table> <tr><td>1</td></tr> <tr><td>2</td></tr> <tr><td>3</td></tr> ...

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.