Chapter Index |
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 cause 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
Copyright ©1996, Que Corporation. All rights reserved. No part of this book may be used or reproduced in any form or by any means, or stored in a database or retrieval system without prior written permission of the publisher except in the case of brief quotations embodied in critical articles and reviews. Making copies of any part of this book for any purpose other than your own personal use is a violation of United States copyright laws. For information, address Que Corporation, 201 West 103rd Street, Indianapolis, IN 46290.Notice: This material is from Perl 5 by Example, ISBN: 0-7897-0866-3. The electronic version of this material has not been through the final proof reading stage that the book goes through before being published in printed form. Some errors may exist here that are corrected before the book is published. This material is provided "as is" without any warranty of any kind.