In perl there are two ways to represent string literals: single-quoted strings and double-quoted strings.
Single quoted are a sequence of characters that begin and end with a single quote. These quotes are not a part of the string they just mark the beginning and end for the Perl interpreter. If you want a ' inside of your string you need to preclude it with a \ like this \' as you'll see below.
Let's see how this works below.
'four' #has four letters in the string
'can\'t' #has five characters and represents "can't"
'hi\there' #has eight characters and represents"hi\\there" (one \ in the string)
'blah\\blah' #has nine characters and represents "blah\\blah" (one \ in the string)
If you want to put a new line in a single-quoted string it goes something like this
line2' #has eleven characters line1, newline character, and then line2
Single-quoted strings don't interpret \n as a newline.
Double quoted strings act more like strings in C or C++ the
backslash allows you to represent control characters. Another
nice feature Double-Quoted strings offers is variable interpolation
this substitutes the value of a variable into the string. Some examples are below
$word="hello"; #$word becomes hello
$statement="$word world"; #variable interpolation, $statement becomes "hello world"
"Hello World\n"; #"Hello World" followed by a newline
Some of the things you can put in a Double-Quoted String
|Representation||What it Means|
|\007||octal ascii value this time 007 or the bell|
|\x07||hex ascii value this time 007 or the bell|
|\cD||any control character.. here it is control-D|
|\l||lowercase next letter|
|\u||uppercase next letter|
|\L||lowercase all letters until \E|
|\U||uppercase all letters until \E|
|\Q||Backslash quote all nonletters and nonnumbers until \E|
|\E||Stop \U \L or \Q|
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||