Open Source Web Development with LAMP Using Linux, Apache, MySQL, Perl, and PHP [Electronic resources]

James Lee, Brent Ware

نسخه متنی -صفحه : 136/ 105
نمايش فراداده

10.4 A Quick Example

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

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

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

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 indexl 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.