Perl,一种功能丰富的计算机程序语言,运行在超过100种计算机平台上,适用广泛,从大型机到便携设备,从快速原型创建到大规模可扩展开发。Perl借取了C、sed、awk、shell 脚本语言以及很多其他程序语言的特性,其中最重要的特性是它内部集成了正则表达式的功能,以及巨大的第三方代码库CPAN。
  3.5. Interpolating Arrays into Strings Like scalars, array values may be interpolated into a double-quoted string. Elements of an array are automatically separated by spaces[*] upon interpolation: [
  3.7. Scalar and List Context This is the most important section in this chapter. In fact, it's the most important section in the entire book. It wouldn't be an exaggeration to say that your entire c
  3.6. The foreach Control Structure It's handy to be able to process an entire array or list, so Perl provides a control structure to do that. The foreach loop steps through a list of values, executi
  4.1. Defining a Subroutine To define your own subroutine, use the keyword sub, the name of the subroutine (without the ampersand), and the indented block of code (in curly braces)[] that makes up th
  3.8. <STDIN> in List Context One previously seen operator that returns a different value in an array context is the line-input operator, <STDIN>. As described earlier, <STDIN> returns the next line
  4.2. Invoking a Subroutine Invoke a subroutine from within any expression by using the subroutine name (with the ampersand):[§] [§] And frequently a pair of parentheses, even if empty. As written, t
  4.4. Arguments That subroutine called larger_of_fred_or_barney would be much more useful if it didn't force you to use the global variables $fred and $barney. If you wanted to get the larger value f
  4.3. Return Values The subroutine is always invoked as part of an expression even if the result of the expression isn't being used. When we invoked &marine earlier, we were calculating the value of
  4.5. Private Variables in Subroutines But if Perl can give us a new @_ for every invocation, can't it give us variables for our own use as well? Of course it can. By default, all variables in Perl a
  4.6. Variable-Length Parameter Lists In real-world Perl code, subroutines are often given parameter lists of arbitrary length. That's because of Perl's "no unnecessary limits" philosophy. Of course,
  4.7. Notes on Lexical (my) Variables Those lexical variables can be used in any block, not merely in a subroutine's block. For example, they can be used in the block of an if, while, or foreach:
  4.8. The use strict Pragma Perl tends to be a permissive language.[] But maybe you want Perl to impose a little discipline; that can be arranged with the use strict pragma. [] Bet you hadn't noticed
  4.9. The return Operator The return operator immediately returns a value from a subroutine: my @names = qw/ fred barney betty dino wilma pebbles bamm-bamm /; my $result = &which_element_is(
  4.10. Non-Scalar Return Values A scalar isn't the only kind of return value a subroutine may have. If you call your subroutine in a list context,[] it can return a list of values. [] You can detect
  5.1. Input from Standard Input Reading from the standard input stream is easy. We've been doing it with the <STDIN> operator.[*] Evaluating this operator in a scalar context gives you the next line
  5.3. The Invocation Arguments Technically, the diamond operator isn't looking at the invocation argumentsit works from the @ARGV array. This array is a special array preset by the Perl interpreter a
  5.2. Input from the Diamond Operator Another way to read input is with the diamond[*] operator: <>. This is useful for making programs that work like standard Unix[] utilities, with respect to the i
  5.5. Formatted Output with printf You may wish to have a little more control with your output than print provides. In fact, you may be accustomed to the formatted output of C's printf function. Fear
  5.4. Output to Standard Output The print operator takes a list of values and sends each item (as a string, of course) to standard output in turn, one after another. It doesn't add any extra characte
5.7. Opening a Filehandle You've seen that Perl provides three filehandlesSTDIN, STDOUT, and STDERRwhich are automatically open to files or devices established by the program's parent process (probabl
  5.6. Filehandles A filehandle is the name in a Perl program for an I/O connection between your Perl process and the outside world. That is, it's the name of a connection and not necessarily the name
  5.8. Fatal Errors with die Let's step aside for a moment. We need some stuff that isn't directly related to (or limited to) I/O but is more about getting out of a program earlier than normal. When a
  5.9. Using Filehandles Once a filehandle is open for reading, you can read lines from it the same way you can read from standard input with STDIN. So, for example, to read lines from the Unix passwo
  5.10. Reopening a Standard Filehandle We mentioned earlier that if you were to reopen a filehandle (that is, if you were to open a filehandle FRED when you've got an open filehandle named FRED), the
  6.1. What Is a Hash? A hash is a data structure like an array, in that it can hold any number of values and retrieve these values at will. However, instead of indexing the values by number, as we di
  6.2. Hash Element Access To access an element of a hash, use syntax that looks like this: $hash{$some_key} This is similar to what we used for array access, but here we use curly braces instead
  6.4. Typical Use of a Hash At this point, a concrete example might help. The Bedrock library uses a Perl program in which a hash tracks how many books each person has checked out: $books{"fred"}
  6.3. Hash Functions Some useful functions can work on an entire hash simultaneously. 6.3.1. The keys and values Functions The keys function yields a list of all the keys in a hash, and the values fu
  7.1. What Are Regular Expressions? A regular expression, often called a pattern in Perl, is a template that matches or doesn't match a given string.[] An infinite number of possible text strings exi
  7.3. Character Classes A character class, a list of possible characters inside square brackets ([ ]), matches any single character from within the class. It matches one character, but that character