Perl Script Learning Guide–Reading Notes

Time:2019-5-17

Undef defaults to undefined characters, Perl does not have NULL, defined ($x) function: if the parameter undef returns false

QW (cs PHY geo) is similar to (“cs”, “phy”, “geo”) lists that can be assigned to an array @array

Array operators: pop, push, shift, unshit, reverse, reverse, @array = [email protected];

[email protected] {print $;} Prints an array; $is a powerful default variable

The each operation returns a pair of @array (index, value) for use in the while loop

Perl has an auto-adapted scalar and list context

Subdefining subroutines (functions), parameters in the @_array, callers available & symbols, not conflicting with the default function can be omitted, can be defined in the function

A persistent private variable of a function, identified by state, that remains the last change every time a function is called

My limits the scope of variables to the current role. Generally, my is used to define variables.

<STDIN> reads the input file by line. By default <> reads all the files in the parameter list. For each line ending withn, chomp can be used to removen.

Printf can format output, sprintf is more powerful

File handle: open CONFIG,’> utf8′,’filename’or die “failed: $!”, die throws an exception, produces an output, close CONFIG;

Use file handles: read files like while (< CONFIG >); change the default output file, select CONFIG; print “123” to CONFIG file, replacing the default STDERR

Hash arrays: key, value arrays; can be assigned to arrays, expand hash; reverse becomes value => key:% EVN environment variable

Keys% hash returns keys array, values% hash returns values array; each returns K, V; exists, delete functions

Powerful regular expressions: A means the beginning, Z means the end, / s matches any blank, brackets can capture variable $1 and survive until the next match succeeds.

No capture mode: /(?: bronto)? AAAA (bb | CC)/ At this time, $1 represents BB or CC; /(?< name1 > w+)/ Named capture, $+{name1};

Automatically capturing variables: $`before matching $& after matching $’; / xxx / P opens capturing variables: high version ${^ MATCH}

S/// substitution, similar to sed, supports capturing $1; U to uppercase

Split / regular /, $string: splitting strings into arrays; join function, the inverse process of split;

Non-greedy quantifiers: +?,*?, {8,}?, do not match greedily; / I ignores case, / M matches line breaks

$^ I = “. bak” updates the file, opens it with filename. bak, and writes back to the original file

Unless (con): similar to if (! Con); until: false condition, repeated execution; last similar to break; next similar to continue; redo back to the beginning of the loop (new); tagged

Various file Testers – e, – M test file information; stat $filename returns a series of file information; [email protected] = glob “*”: all file names for the current path

String function: index, substr; advanced sort @res = sort {$a<==> $b & &$a CMP $b} @array

Intelligent matcher: ~: matches hash’s key, whether the array is the same

Given-when statement: similar to switch, there are continue and break;

System adds commands to execute subprocesses; exec runs to another process and Perl no longer executes; inversion marks capture return values;

Support fork multi-process; define (my $pid = fork) or die “$!”; unless ($pid) {sub-process work}; support sending and receiving SIG;

Slice: ($first, $last) = ([email protected]) [0, -1], arrays, hash can be; Eval capture error is not returned;

Grep: my @array = grep {$% 2} 1.1000; odd array; my @array = map {& big_money ($)} @data; operation on each element in data; all return lists

Recommended Today

Introduction to node

This is going to be a very long article Start with a simple server // server.js const http = require(‘http’) const server = http.createServer(() => { Console.log (‘rotate 300 circles in place and listen to 3000 ports’) }) server.listen(3000) First run at the terminalnode server.jsUse browser to enter in address barlocalhost:3000The console will be printed […]