<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="en"> <head> <title> WebMake: Documentation: The <{perl}> Directives </title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta name="generator" content="WebMake/2.3" /> <style type="text/css"> body { background-color: #ffffff; color: #000000; line-height: 110%; margin-left: 10px; margin-right: 10px; } p, table, td, th { font-family: verdana,lucida,helvetica,sans-serif; font-size: 11px; line-height: 110%; } pre { margin-left: 3%; white-space: pre; } code, samp, pre, p pre { font-family: "lucida console", "Courier New", courier, "fixed-width", monospace; font-weight: bold; } H1 { font-size: 150%; font-family: Garamond, "Book Antiqua",Times,serif; background: #FFCC66; text-align: center; padding: 0.5em 1em 0.5em 1em; border-width: 1px; border-color: black; border-style: solid; line-height: 120%; } H2 { font-size: 125%; font-family: Garamond, "Book Antiqua",Times,serif; background: #FFDD77; text-align: center; padding: 0.5em 1em 0.5em 1em; border-width: 1px; border-color: black; border-style: solid; line-height: 100%; } H3 { font-size: 100%; font-family: Garamond, "Book Antiqua",Times,serif; background: #FFEE88; text-align: center; padding: 0.5em 1em 0.5em 1em; border-width: 1px; border-color: black; border-style: solid; } H4 { font-size: 75%; font-family: Garamond, "Book Antiqua",Times,serif; } H5 { font-size: 50%; font-family: Garamond, "Book Antiqua",Times,serif; } H6 { font-size: 25%; font-family: Garamond, "Book Antiqua",Times,serif; } A:link { font-weight: bold; color: #004000; text-decoration: underline; } A:visited { font-weight: bold; color: #008000; text-decoration: underline; } A:active { font-weight: bold; color: #800000; text-decoration: underline; } dt { font-size: medium; font-weight: bold; padding-top: 8px; padding-bottom: 8px; } dd { padding-top: 8px; padding-bottom: 8px; } </style> </head> <body bgcolor="#ffffff" text="#000000" link="#3300cc" vlink="#660066"> <!-- font tag for compat with non-CSS browsers --> <font face="lucida,verdana,sans-serif"> <div align="center"> <img src="images/WebMakeTitle.png" alt="WebMake" width="500" height="122" /> </div> <table width="100%"> <tr> <td valign="top"> <strong><a href="http://webmake.taint.org/">WebMake</a> Documentation</strong> (version 2.3) </td> <td valign="top"> <div align="right"> [ <a href="set.html">Back</a> | <a href="sorting.html">Forward</a> | <a href="index.html">Index</a> | <a href="allinone.html">All In One</a> ] </div> </td> </tr> </table> <!-- yes, it's that Mozilla black-border code again ;) --> <!-- stolen from www.mozilla.org via rc3.org --> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td bgcolor="#aaaaaa"> <table border="0" cellspacing="4" cellpadding="4" width="100%"> <tr> <td bgcolor="#ffffff"> <table border="0" cellspacing="4" cellpadding="4" width="100%"> <tr> <td> <h1>The <{perl}> Directives</h1><p> Arbitrary perl code can be executed using this directive. </p> <p> It works like perl's <code>eval</code> command; the return value from the perl block is inserted into the file, so a perl code block like this: </p> <p> <pre> <{perl $_ = ''; for my $fruit (qw(apples oranges pears)) { $_ .= " ".$fruit; } $_; }> </pre> </p> <p> will be replaced with the string " apples oranges pears". Note that the <code>$_</code> variable is declared as local when you enter the perl block, you don't have to do this yourself. </p> <p> If you don't like the eval style, you can use a more PHP/JSP/ASP-like construct using the <code>perlout</code> directive, which replaces the perl code text with anything that the perl code prints on the default output filehandle, like so: </p> <p> <pre> <{perlout for my $fruit (qw(apples oranges pears)) { print " ", $fruit; } }> </pre> </p> <p> Note that this is not STDOUT, it's a local filehandle called <code>$outhandle</code>. It <em>is</em> selected as the default output handle, however, so just <code>print</code> without a filehandle name will work. </p> <p> Also, it should be noted that <code>perl</code> is a little more efficient than <code>perlout</code>, so if you're going all-out for speed, you should use that. </p> <p> <a href="perl.html"><{perl}></a> sections found at the top level of the WebMake file will be evaluated during the file-parsing pass, as they are found. </p> <p> <a href="perl.html"><{perl}></a> sections embedded inside content chunks or other tagged blocks will be evaluated only once they are referenced. </p> <p> Perl code can access content variables and URLs using the <a href="PerlCodeLibrary.pm.html">library functions provided</a>. </p> <p> The library functions are available both as normal perl functions in the default <code>main</code> package, or, if you want to write thread-safe or mod_perl-safe perl code, as methods on the <code>$self</code> object. The <code>$self</code> object is available as a local variable in the perl code block. </p> <p> A good example of perl use inside a WebMake file can be found in the <code>news_site.wmk</code> file in the <em>examples</em> directory. </p> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> <table width="100%"> <tr> <td valign="top"> <strong><a href="http://webmake.taint.org/">WebMake</a> Documentation</strong> (version 2.3) </td> <td valign="top"> <div align="right"> [ <a href="set.html">Back</a> | <a href="sorting.html">Forward</a> | <a href="index.html">Index</a> | <a href="allinone.html">All In One</a> ] </div> </td> </tr> </table> <div align="right"> <a href="http://webmake.taint.org/"> <img src="images/BuiltWithWebMake.png" alt="Built With WebMake" border="0" width="88" height="31" /></a> </div> </font> </body> </html>