Open Source Web Development with LAMP Using Linux, Apache, MySQL, Perl, and PHP [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Open Source Web Development with LAMP Using Linux, Apache, MySQL, Perl, and PHP [Electronic resources] - نسخه متنی

James Lee, Brent Ware

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید










11.4 A Quick Example


Let's show an example. We create the file /var/www/html/mason/testl and place the following contents within it:
[1]

[1] Set the permissions to 644, but you already knew that, right?



% my $name = ´John Doe´;
<html>
<head>
<title>Mason Example</title>
</head>
<body bgcolor="#ffffff">
Hello, <% $name %>!
<br>2 + 3 = <% 2 + 3 %>
</body>
</html>

You will notice right away that our first Mason example is not "hello, world!". We apologize for the inconsistency.

At the top of this file is % my $name = ´John Doe´;. The character "%" indicates that this line is Perl code to be executed.
[2] The variable $name is defined using the my() function. Global variables in Mason must be my() variablesif they are not declared with my(), a syntax error is generated.

[2] For lines that begin with "%," that "%" must be the first character in the line.


The Perl code within <% ... %> is executed, and what that code evaluates to is replaced in the HTML file (much like Embperl's [+ ... +]). Therefore, <% $name% > is replaced with the value John Doe, and <% 2 + 3 %> is replaced with the result 5.

Try this page by loading either of the following URLs: http://localhost/mason/testl or www.opensourcewebbook.com/mason/testl. This should display a page similar to Figure 11.1.


Figure 11.1. Mason example



/ 136