Open Source Development with LAMP: Using Linux, Apache, MySQL, Perl, and PHP

Let's start with a quick example to display "hello, world!" with Embperl (what else?). Create the file /var/www/html/embperl/index.html with the following contents (remember to chmod a+r index.html [3] ):

[3] In general, if you have any problems, check your permissions. Don't make us say this again.

[- $msg = hello, world!; -] <html> <head> <title>hello, world with Embperl</title> </head> <body bgcolor="#ffffff"> [+ $msg +] </body> </html>

To see the result of this page, load one of the following into your browser: http://localhost/embperl/ or www.opensourcewebbook.com/embperl/. You should see something like Figure 10.1.

Figure 10.1. hello, world! with Embperl

The first part of index.html is an Embperl command denoted by [- ... -] . We discuss this later in this chapter, but for now suffice it to say that the code within this command is executed as Perl code. In this example, $msg is set to a familiar message that is included in the HTML within the <body> tags.

To include the contents of the variable $msg , use the Embperl command [+ $msg +] . This command is replaced by the value of the variable $msg . This value is then displayed in the browser.

Категории