Go to the first, previous, next, last section, table of contents.

Perl Goodbye World


# Tell Perl where to look for wafe-specific libraries:
$WafeLib = $ENV{'WAFELIB'} || "/usr/local/lib/wafe";

# Load a library of wafe-specific convenience functions:
require "$WafeLib/perl/wafe.pl";

# Feed the widget definitions to WAFE via stdout.
# We use Xui, which is one of the wafe.pl convenience
# functions: It simply sends all given text to
# stdout and thence to the WAFE process.
# Note we need \\ not \ at end of line here:
    Command c topLevel \\
        label "Goodbye World!" \\
        callback {puts Goodbye; quit}

# Loop reading and respond to
# callback-generated text from
# the WAFE process, read via
# stdin using another wafe.pl
# convenience function:
while ($_ = &wafe'read) {
    last if /^Goodbye/;

The code should be reasonably self-explanatory.

Xui ("ui" for User Interface) is a convenience function defined by wafe.pl which passes the given string to WAFE, and <<"End_Tcl" is a Perl convention meaning that the actual argument consists of all following lines of text up to the next line reading "End_Tcl". The & operator is one Perl syntax for invoking a function.

read is another convenience function defined by wafe.pl, which reads one line from the WAFE process: wafe'read is Perl syntax for accessing the function named read within the package named wafe.

The --p switch tells WAFE to execute commands from the given program, which is forked off with stdin and stdout redirected to the WAFE process. WAFE searches for the program in the directories specified by the standard PATH environment variable.

Go to the first, previous, next, last section, table of contents.