2016年9月17日 星期六

perl quotes

Alternative Quotes: qq, q, qw, qx

print qq/Hello\n/;                  # same as: print "Hello\n";
print q/He owes $5.00/;       #  same as: print 'He owes $5.00', "\n";
@states=qw( E T A L );       # same as ("E", "T", "A","L")
$today = qx(date);               # same as $today = 'date'; 



While we usually think of quotes as literal values,
in Perl they function as operators,
providing various kinds of interpolating and pattern matching capabilities.
Perl provides customary quote characters for these behaviors,
but also provides a way for you to choose your quote character for any of them.
In the following table, a "{}" represents any pair of delimiters you choose.

Customary  Generic        Meaning        Interpolates
                 ''       q{}          Literal             no
               ""      qq{}          Literal             yes
               ``      qx{}          Command             yes*
                        qw{}         Word list            no
                //       m{}       Pattern match          yes*
                         qr{}          Pattern             yes*
                         s{}{}      Substitution          yes*
                         tr{}{}    Transliteration         no (but see below)
              <<EOF                 here-doc            yes*

    * unless the delimiter is ''.