| |||
Links Sections Chapters Part I: Basic Perl 02-Numeric and String
Literals Part II: Intermediate Perl Part III: Advanced Perl 13-Handling Errors and
Signals Part IV: Perl and the Internet 21-Using Perl with Web
Servers Appendixes |
Escape Sequences | Description or Character |
---|---|
\a | Alarm\bell |
\b | Backspace |
\e | Escape |
\f | Form Feed |
\n | Newline |
\r | Carriage Return |
\t | Tab |
\v | Vertical Tab |
\$ | Dollar Sign |
\@ | Ampersand |
\% | Percent Sign |
\0nnn | Any Octal byte |
\xnn | Any Hexadecimal byte |
\cn | Any Control character |
\l | Change the next character to lower case |
\u | Change the next character to upper case |
\L | Change the following characters to lowercase until a \E sequence is encountered |
\U | Change the following characters to uppercase until a \E sequence is encountered |
\E | Terminate the \L or \U sequence |
\\ | Backslash |
print `dir c:\*.log`;This would display all files with the extension of LOG on a DOS system.
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
$firstVar = 5; { if ($firstVar > 10) { last; } $firstVar++; redo; } print("$firstVar\n");This program will display:
11
print("${\ref(\(1..5))}");This code will display:
ARRAY
open(FILE_ONE, ">FILE_ONE.DAT"); open(FILE_TWO, ">>FILE_TWO.DAT");The > character causes the file to be opened for writing and causes any existing data in the file to be lost. Whereas the >> character sequence will open the file for appending-preserving the existing data.
(stat("09lst01.pl"))[7];This expression will return the size of the file.
printf("%x", 16);The statement displays:
10
m{.*];When using curly braces as alternative delimiters, the end delimiter must be }.
/AA[.<]$]ER/The $ is the beginning character of the special variable $].
$_ = 'AB AB AC'; print m/c$/i;This program displays:
1
format FORMATNAME = FIELD_LINE VALUE_LINE .
select((select(ANNUAL_RPT), $^ = "REGIONAL_SALES")[0]);First the ANNUAL_RPT file handle will be selected as the default file handle for the print and write statements and then the $~ variable will be changed to the new format name. By enclosing the two statements inside parentheses their return values will be used in an array context. Since the select function returns the value of the previous default file handle, after executing the second select() the default file handle will be restored to its previous value.
$_ = "The big red shoe"; m/[rs].*\b/; print("$`\n");This program displays:
The Big
@array = (1..5); $" = "+"; print("@array\n");This program displays:
1+2+3+4+5
@array = ('A'..'E'); foreach (@array) { print(); } $\ = "\n"; foreach (@array) { print(); }This program displays:
ABCDEA B C D E