10.07.2015 Views

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

284APPENDIX ■ PERL BASICSKeywordsA keyword is a term in <strong>Perl</strong> that has a predefined meaning. One example is the term use as wesaw in the statementuse warnings;Other types of keywords include built-in functions such as print() and control flowconstructs such as if and while. We will talk about many built-in functions and control flowconstructs in detail as we progress in our discussion of <strong>Perl</strong>.It’s a good idea <strong>to</strong> respect keywords and not give anything else the same name as one. Forexample, a little later on you’ll learn that you can create and name a variable, and that callingyour variable $print is perfectly allowable. The problem with this is that it leads <strong>to</strong> confusingand uninformative statements like print $print. It is always a good idea <strong>to</strong> give a variablea meaningful name, one that relates <strong>to</strong> its content in a logical manner—for example, $my_name,@telephone_numbers, %account_info, and so on, rather than $a, @b, and %c.Statements and Statement BlocksIf functions are the verbs of <strong>Perl</strong>, then statements are the sentences. Instead of a period,a statement in <strong>Perl</strong> usually ends with a semicolon, as shown earlier:print "Hello, world!\ n";To print some more text, we can add another statement:print "Hello, world!\ n";print "Goodbye, world!\ n";Escape SequencesUTF8 gives us 65,536 characters, and ASCII gives us 256 characters, but on the average keyboard,there’s only a hundred or so keys. Even using the Shift keys, there will still be somecharacters that you aren’t going <strong>to</strong> be able <strong>to</strong> type. There will also be some things that youdon’t want <strong>to</strong> stick in the middle of your program, because they would make it messy or confusing.However, you’ll want <strong>to</strong> refer <strong>to</strong> some of these characters in strings that you output.<strong>Perl</strong> provides us with mechanisms called escape sequences as an alternative way of getting <strong>to</strong>them. You’ve already seen the use of \ n <strong>to</strong> start a new line. Table A-1 lists the more commonescape sequences.Table A-1. Escape SequencesEscape Sequence Meaning\ t Tab\ n Start a new line (usually called newline)\ r Carriage return\ b Back up one character (backspace)\ a Alarm (rings the system bell)\ x{ 1F18} Unicode character

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!