Lemur zaprasza
Red Hat® Linux 6 Unleashed
Chapter 31: Perl Programming Previous
Sections in this Chapter: A Simple Perl Program Regular Expressions Perl Variables and Data Structures Access to the Shell For More Information Conditional Statements: if/else and unless Modules and CPAN Previous SectionNext Section Chapter 31 Perl Programming by Rich Bowen Perl (Practical Extraction and Report Language) was
Perl, according to Larry, is all about "making easy things
Perl contains the best features of C, Basic, and a variety of
Perl is an interpreted language. The interpreter has been ported
A Simple Perl Program To introduce you to the absolute basics of Perl programming, Listing 31.1 illustrates a trivial Perl program. LISTING 31.1 A Trivial Perl Program #!/usr/bin/perl print "Look at all the camels!\n"; That's the whole thing. Type that in, save it to a file called trivial.pl, chmod +x it, and execute it. The #! line is technically not part of the Perl code at all ( the # character is the comment character in Perl), but is instead a message to the shell, telling it where it should go for the executable to run this program. That is standard practice in shell programming, as is discussed in Chapter 25, "Shell Programming." If, for some reason, Perl is not located at /usr/bin/perl on your system, you can locate the correct location of Perl by using the which command. Note - #! is often pronounced "she-bang," which is short for "sharp," (the musical name for the # character) and "bang," which is another name for the exclamation point. which perl If you do not have Perl installed, you might want to skip to "For More Information" in this chapter to find out where you can obtain the Perl interpreter. However, a version of Perl comes with Red Hat, so this should not be the case. The second line does precisely what you would expect--it prints the text enclosed in quotation marks. \n is the escape sequence for a newline character.Perl statements are terminated with a semicolon. A Perl statement can extend over several actual screen lines. Alternatively, you can have Perl statements in one line. Perl is not particularly concerned about whitespace.The # character indicates that the rest of the screen line is a comment. That is, there is a comment from the # character until the next newline and it is ignored by the interpreter. Exceptions to this include when the # character is in a quoted string and when it is being used as the delimiter in a regular expression.A block of code, such as what might appear inside a loop or a branch of a conditional statement, is indicated with curly braces ({}). Included with the Perl installation is a document called perlfunc, which lists all of the available Perl functions and their usage. You can view this document by typing perldoc perlfunc at the command line. You can also find this document online at . Red Hat® Linux 6 Unleashed
Chapter 31: Perl Programming Previous
Sections in this Chapter: A Simple Perl Program Regular Expressions Perl Variables and Data Structures Access to the Shell For More Information Conditional Statements: if/else and unless Modules and CPAN Previous SectionNext Section © Copyright Macmillan USA. All rights reserved. |