Sharing data between active parts
All active contents shares the same Safe object which means that it is executed in the same Perl namespace (which usually happens to appear as main::
, please see the translators documentation for details). As a consequece, several parts can interact with each other by variables and functions.
Note that the active parts are evaluated in the order they appear in the PerlPoint source.
\EMBED{lang=perl}
sub fileCount
{
# get number of files
opendir(D, '.');
my @fileNr=readdir(D);
my $fileNr=@fileNr;
closedir(D);
# supply result
$fileNr;
}
# scan directory
$filesFound=fileCount;
'';
\END_EMBED
|
The following condition evaluates the number of files found by the previously executed code, using a variable set there:
// conditional hints
? $filesFound>10000000000 |
.. and includes more informations if appropriate:
=Using directories
The number of files in your directory let us add additional suggestions:
...
// back to main document
? 1 |
Now we can use the previously declared function again:
There are \EMBED{lang=perl}fileCount\END_EMBED files
in the current directory. |