| Lesson 3 - Print Statement |
| Print Basic Output is
the most important part of any language. Without a print statement,
you would never be able to communicate In this topic we
will discuss the use of the print statement in PERL. You will learn
how to write a basic "Hello, World" A sample print statement
to print out "modus operandi" looks like this: Let's examine the
statement. The command portion of the statement, "print,"
lets perl know that we want to print something. Without the quotes
around our data, perl will not know where to stop outputting and therefore
miss the semicolon which tells You've now learned how to output data to STDOUT. Lets take a look at write data to a web browser. Web browsers needs
certain headers in order to correctly display data. The only header
we need to worry about is Most of the time
we will want to output our data as either plain text of HTML. Here is
an example of standard output in HTML print
"Content-Type: text/html\n\n"; If you do not output
the Content-Type header first, or you neglect to include two \n's after
it, the server will return In the case that
you would like to output to a file or some other device you can simply
specify what you wish to write to in open
(OUT, "testfile"); In order to establish
the OUT handle you need to use the open command first. This will be
discussed in a later topic, for now The last topic we
will discuss is escaping characters. For perl to know where to begin
and end the data your are trying to print "\"this is quoted\""; By printing a `\"`
perl will print out a `"`. You can use escape sequences for other
uses as well, `\t` will print a tab, print "$14.95"; In the above command
perl will print out the contents of the string "$14" and then
".95". If you have not put any data into In order to tell
perl not to do this, you need to escape it. To print out "$14.95"
instead of ".95" run the command like print "\$14.95"; Another option to
escaping variables is to use `'` characters instead of `"` characters.
By using single quotes like In this lesson you
learned the basic use of the print statement in PERL, how to write data
out to users and to a web browser.
|