![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Perl
文章平均质量分 87
zp_mouse
这个作者很懒,什么都没留下…
展开
-
Learning Perl: 10.1. The unless Control Structure
<br /> 10.1. The unless Control Structure<br />In an if control structure, the block of code is executed only when the conditional expression is true. If you want to execute a block of code only when the conditional is false, change if to unless: unless原创 2010-07-21 18:00:00 · 452 阅读 · 0 评论 -
Perl Learning: 2.6. The if Control Structure
<br /> 2.6. The if Control Structure<br />Once you can compare two values, you'll probably want your program to make decisions based upon that comparison. Like all similar languages, Perl has an if control structure: if ($name gt 'fred') { print原创 2010-07-21 17:17:00 · 326 阅读 · 0 评论 -
Learning Perl: 9.4. m// in List Context
<br /> 9.4. m// in List Context<br />When you use split, the pattern specifies the separator: the part that isn't the useful data. Sometimes it's easier to specify what you want to keep.<br />When a pattern match (m//) is used in a list context, the return原创 2010-07-21 17:59:00 · 383 阅读 · 0 评论 -
Learning Perl: 8.9. A Pattern Test Program
<br /> 8.9. A Pattern Test Program<br />When in the course of Perl events it becomes necessary for a programmer to write a regular expression, it may be difficult to tell what the pattern will do. It's normal to find that a pattern matches more than you ex原创 2010-07-21 17:58:00 · 313 阅读 · 0 评论 -
Perl Learning: 8.2. Option Modifiers
<br /> 8.2. Option Modifiers<br />Several option modifier letters, sometimes called flags, may be appended as a group right after the ending delimiter of a regular expression to change its behavior from the default.8.2.1. Case-Insensitive Matching with /i<原创 2010-07-21 17:54:00 · 408 阅读 · 0 评论 -
Learning Perl: 7.2. Using Simple Patterns
<br /> 7.2. Using Simple Patterns<br />To match a pattern (regular expression) against the contents of $_, put the pattern between a pair of forward slashes (/) as we do here: $_ = "yabba dabba doo"; if (/abba/) { print "It matched!/n";原创 2010-07-21 17:53:00 · 552 阅读 · 0 评论 -
Learning Perl: 7.1. What Are Regular Expressions?
<br /> 7.1. What Are Regular Expressions?<br />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 exist, and a given pattern divides that infinite原创 2010-07-21 17:52:00 · 390 阅读 · 0 评论 -
Learning Perl: 6.4. Typical Use of a Hash
<br /> 6.4. Typical Use of a Hash<br />At this point, a concrete example might help.<br />The Bedrock library uses a Perl program in which a hash tracks how many books each person has checked out: $books{"fred"} = 3; $books{"wilma"} = 1;<br /><br /原创 2010-07-21 17:51:00 · 370 阅读 · 0 评论 -
Learning Perl:
<br /> 6.2. Hash Element Access<br />To access an element of a hash, use syntax that looks like this: $hash{$some_key}<br /><br />This is similar to what we used for array access, but here we use curly braces instead of square brackets around the subscr原创 2010-07-21 17:50:00 · 422 阅读 · 0 评论 -
Learning Perl: 6.1. What Is a Hash?
<br /> 6.1. What Is a Hash?<br />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 did with arrays, we'll look up the values by nam原创 2010-07-21 17:49:00 · 409 阅读 · 0 评论 -
Learning Perl: 5.6. Filehandles
<br /> 5.6. Filehandles<br />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 of a file.<br />Filehandles are named like ot原创 2010-07-21 17:44:00 · 374 阅读 · 0 评论 -
Learning Perl: 5.1. Input from Standard Input
<br /> 5.1. Input from Standard Input<br />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 of input:<br />[*] What we're calling the line原创 2010-07-21 17:36:00 · 337 阅读 · 0 评论 -
Learning Perl: 4.8. The use strict Pragma
<br /> 4.8. The use strict Pragma<br />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.<br />[] Bet you hadn't noticed.<br />A pragma is a hint to a compiler,原创 2010-07-21 17:33:00 · 399 阅读 · 0 评论 -
Learning Perl: 4.7. Notes on Lexical (my) Variables
<br /> 4.7. Notes on Lexical (my) Variables<br />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: foreach (1..10) { my($square) = $_ * $_原创 2010-07-21 17:32:00 · 329 阅读 · 0 评论 -
Learning Perl: 4.5. Private Variables in Subroutines
<br /> 4.5. Private Variables in Subroutines<br />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.<br />By default, all variables in Perl are global variables; that is, they are ac原创 2010-07-21 17:30:00 · 334 阅读 · 0 评论 -
Learning Perl: 4.4. Arguments
<br /> 4.4. Arguments<br />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 from $wilma and $betty, you currently have to c原创 2010-07-21 17:29:00 · 325 阅读 · 0 评论 -
Learning Perl: 4.1. Defining a Subroutine
<br /> 4.1. Defining a Subroutine<br />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 the body of the subroutine, something like this:原创 2010-07-21 17:27:00 · 260 阅读 · 0 评论 -
Perl Learning: 2.10. The undef Value
<br /> 2.10. The undef Value<br />What happens if you use a scalar variable before you give it a value? Nothing serious and definitely nothing fatal. Variables have the special undef value before they are first assigned, which is Perl's way of saying "noth原创 2010-07-21 17:21:00 · 276 阅读 · 0 评论 -
Learning Perl: 2.11. The defined Function
<br /> 2.11. The defined Function<br />One operator that can return undef is the line-input operator, <STDIN>. Normally, it returns a line of text. But if there is no more input, such as at end-of-file, it will return undef to signal this.[*] To tell if a原创 2010-07-21 17:22:00 · 194 阅读 · 0 评论 -
Learning Perl: 9.3. The join Function
<br /> 9.3. The join Function<br />The join function doesn't use patterns but performs the opposite function of split: split breaks up a string into a number of pieces, and join glues together a bunch of pieces to make a single string. The join function lo原创 2010-07-21 17:59:00 · 336 阅读 · 0 评论 -
Learning Perl: 8.8. Precedence
<br /> 8.8. Precedence<br />With all of these metacharacters in regular expressions, you may feel you can't keep track of the players without a scorecard. That's the precedence chart, which shows us which parts of the pattern stick together the most tightl原创 2010-07-21 17:57:00 · 405 阅读 · 0 评论 -
Learning Perl: 8.4. The Binding Operator, =~
<br /> 8.4. The Binding Operator, =~<br />Matching against $_ is merely the default; the binding operator (=~) tells Perl to match the pattern on the right against the string on the left, instead of matching against $_.[] For example:<br />[] The binding o原创 2010-07-21 17:55:00 · 461 阅读 · 0 评论 -
Perl Learning: 5.10. Reopening a Standard Filehandle
<br /> 5.10. Reopening a Standard Filehandle<br />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 old one would be closed for you automatically原创 2010-07-21 17:47:00 · 398 阅读 · 0 评论 -
Learning Perl: 5.5. Formatted Output with printf
<br /> 5.5. Formatted Output with printf<br />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 notPerl provides a comparable operation with原创 2010-07-21 17:38:00 · 427 阅读 · 0 评论 -
Learning Perl: 5.4. Output to Standard Output
<br /> 5.4. Output to Standard Output<br />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 characters before, after, or in between the items.[*]原创 2010-07-21 17:38:00 · 317 阅读 · 0 评论 -
Learning Perl: 5.2. Input from the Diamond Operator
<br /> 5.2. Input from the Diamond Operator<br />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 invocation arguments (which we'll see in a mome原创 2010-07-21 17:37:00 · 339 阅读 · 0 评论 -
Learning Perl: 4.10. Non-Scalar Return Values
<br /> 4.10. Non-Scalar Return Values<br />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.<br />[] You can detect if a subroutine is being evaluated in a s原创 2010-07-21 17:35:00 · 313 阅读 · 0 评论 -
Learning Perl: 4.9. The return Operator
<br /> 4.9. The return Operator<br />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("dino", @names); sub which_element_is {原创 2010-07-21 17:34:00 · 276 阅读 · 0 评论 -
Learning Perl: 4.6. Variable-Length Parameter Lists
<br /> 4.6. Variable-Length Parameter Lists<br />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, this is unlike many traditional programming l原创 2010-07-21 17:31:00 · 527 阅读 · 0 评论 -
Learning Perl: 4.3. Return Values
<br /> 4.3. Return Values<br />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 the expression containing the invocation but t原创 2010-07-21 17:29:00 · 304 阅读 · 0 评论 -
Learning Perl: 3.8. in List Context
<br /> 3.8. <STDIN> in List Context<br />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 of input in a scalar context. Now, in list con原创 2010-07-21 17:27:00 · 310 阅读 · 0 评论 -
Learning Perl: 3.6. The foreach Control Structure
<br /> <br />3.6. The foreach Control Structure<br />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, executing one iteration (time through the loo原创 2010-07-21 17:26:00 · 283 阅读 · 0 评论 -
Learning Perl: 3.3. List Literals
<br /> 3.3. List Literals<br />An array (the way you represent a list value within your program) is a list of comma-separated values enclosed in parentheses. These values form the elements of the list: (1, 2, 3) # list of three values 1, 2, and 3原创 2010-07-21 17:24:00 · 275 阅读 · 0 评论 -
Learning Perl: 3.1. Accessing Elements of an Array
<br /> 3.1. Accessing Elements of an Array<br />If you've used arrays in another language, you won't be surprised to find Perl provides a way to subscript an array to refer to an element by a numeric index.<br />The array elements are numbered using sequen原创 2010-07-21 17:23:00 · 257 阅读 · 0 评论 -
Learning Perl: 2.12. Exercises
<br /> 2.12. Exercises<br />See Appendix A for answers to the following exercises:<br />[5] Write a program that computes the circumference of a circle with a radius of 12.5. Circumference is 2p times the radius (approximately 2 times 3.141592654). The ans原创 2010-07-21 17:22:00 · 260 阅读 · 0 评论 -
Perl: 3.5. Interpolating Arrays into Strings
<br /> 3.5. Interpolating Arrays into Strings<br />Like scalars, array values may be interpolated into a double-quoted string. Elements of an array are automatically separated by spaces[*] upon interpolation:<br />[*] The separator is the value of the spec原创 2010-07-21 17:25:00 · 328 阅读 · 0 评论 -
Learning Perl: 3.4. List Assignment
<br /> 3.4. List Assignment<br />In much the same way as scalar values, list values may be assigned to variables: ($fred, $barney, $dino) = ("flintstone", "rubble", undef);<br /><br />All three variables in the list on the left get new values, as if you原创 2010-07-21 17:24:00 · 382 阅读 · 0 评论 -
Learning Perl: 1.4. How Do I Make a Perl Program?
<br /> 1.4. How Do I Make a Perl Program?<br />It's about time you asked (even if you didn't). Perl programs are text files; you can create and edit them with your favorite text editor. (You don't need any special development environment, though some comme原创 2010-07-21 17:09:00 · 1100 阅读 · 0 评论 -
Learning Perl: 10.6. Autoincrement and Autodecrement
<br /> 10.6. Autoincrement and Autodecrement<br />You'll often want a scalar variable to count up or down by one. Since these are frequent constructs, there are shortcuts for them like nearly everything else we do frequently.<br />The autoincrement operato原创 2010-07-21 18:04:00 · 404 阅读 · 0 评论 -
Learning Perl: 10.4. The Naked Block Control Structure
<br /> 10.4. The Naked Block Control Structure<br />The so-called "naked" block is one without a keyword or condition. That is, suppose you start with a while loop, which looks something like this: while (condition) { body; body; bo原创 2010-07-21 18:02:00 · 459 阅读 · 0 评论