听烂漫音乐,看美丽世界,过精彩生活……

发布新日志

  • Perldoc

    2009-05-31 14:39:00

    Perl代有机器庞大的文档库,采用man形式存放。如果要查找某一特定的函数,手工查找会非
    常困难。但是perldoc命令,可以帮你轻松找到所需要的资料:

    假设我们要查找sort函数的手册,那么:

    perldoc-f sort

    就会告诉你sort的用法,如果还有疑问,可以搜索FAQ
  • Perl - study note - single & double quoted string

    2009-05-29 23:10:50

    One major difference between double- and single-quoted strings is that double-quoted strings have some special escape sequences that can be used. Escape sequences represent characters that are not easily entered using the keyboard or that are difficult to see inside an editor window. The following are all of the escape sequences that Perl understands are given in Table

    Table 2.1: Perl Escape Sequences
    Escape Sequences Description or Character
    \b Backspace
    \e Escape
    \f Form. Feed
    \n Newline
    \r Carriage Return
    \t Tab
    \v Vertical Tab
    \$ Dollar Sign
    \@ Ampersand
    \0nnn Any Octal byte
    \xnn Any Hexadecimal byte
    \cn Any Control character
    \l Change the next character to lowercase
    \u Change the next character to uppercase
    \L Change the following characters to
      lowercase until a \E
      sequence is encountered.
      Note that you need to use an
      uppercase E here, lowercase
      will not work.
    \Q Quote meta-characters as literals.
    \U Change the following characters
      to uppercase until a \E
      sequence is encountered. Note that you
      need to use an uppercase E
      here,
      lowercase will not work.
    \E Terminate the \L, \Q,
      or \U sequence.
      Note that you need to use an
      uppercase E here, lowercase will not work.
    \\ Backslash

    Note In the next chapter we'll see why you might need to use a backslash when using the $ and @ characters.

    The examples following the table will illustrate some of them.

    "\udave \umarshall is \x35\x years
    old."

    This literal represents the following: Dave Marshall is 35 years old.

    The \u is used twice in the first word to capitalize the d and m characters. And the hexadecimal notation is used to represent the age using the ASCII codes for 3 and 5.

    "The kettle was \Uhot\E!"

    This literal represents the following: The kettle was HOT!. The \U capitalizes all characters until a \E sequence is seen.

    A final example:

    print "Bill of Goods



    Bread:\t\$34.45\n";

    print "Fruit:\t";

    print "\$45.00\n";

    print "\t======\n";

    print "\t\$79.45\n";

    Actually, this example isn't too difficult, but it does involve looking at more than one literal at once and it's been a few pages since our last advanced example. Let's look at the \t and \n escape sequences.

    This program uses two methods to cause a line break.

    • The first is simply to include the line break in the source code.
    • The second is to use the \n or newline character.

Open Toolbar