The /g modifier specifies global pattern matching–that is, matching as many times as possible within the string. In list context, it returns a list of the substrings matched by any capturing parentheses in the regular expression. If there are no parentheses, it returns a list of all the matched strings, as if there were parentheses around the whole pattern. The ~~ operator compares its operands “polymorphically”, determining how to compare them according to their actual types (numeric, string, array, hash, etc.). Like the equality operators with which it shares the same precedence, ~~ returns 1 for true and “” for false.
Unicode support
Here the first line will load Carp unless it is the parser who called the handler. The second line will print backtrace and die if Carp was available. The third line will be executed only if Carp was not available.
Note there is a distinction between a capture buffer which matches the empty string a capture buffer which is optional. It is a known issue that goto LABEL may interact poorly with the dynamically scoped match context. This may not be fixable, and is considered to be one of many good reasons to avoid goto LABEL. The require__after hook is called for each required file in FILO order. In other words if A requires B requires C, then require__after will be called first for C, then B and then A.
Because what actually happens is mostly determined by the type of the second operand, the table is sorted on the right operand instead of on the left. Binary ~~ does a “smartmatch” between its arguments. This is mostly used implicitly in the when construct described in perlsyn, although not all when clauses call the smartmatch operator.
#Variables related to regular expressions
The require operator uses this hash to determine whether a particular file has already been included. On some (but not all) operating systems assigning to $0 modifies the argument area that the ps program sees. On some platforms you may have to use special ps options or a different ps to see the changes. Modifying the $0 is more useful as a way of indicating the current program state than it is for hiding the program you’re running.
When $/ is set to undef (sometimes known as file-slurp mode) and the file is empty, it returns ” the first time, followed by undef subsequently. This section hopes to clarify how Perl handles quoted constructs. The allowed elements are literals plus \’ (meaning a single quote). If the delimiters aren’t single quotes, also allowed are any of the escape sequences accepted in double-quoted strings. Escape sequence details are in the table near the beginning of this section. In scalar context, each execution of m//g finds the next match, returning true if it matches, and false if there is no further match.
#List of Extra Paired Delimiters
- Perl was made to be a glue language, and one of the things it glues together is commands.
- See perlopentut and “open” in perlfunc for details on this.
- In this example, these are the ASCII printable characters.
- (See “Arrays” in perlintro.) The two have nothing to do with each other.
- The result is the character specified by the hexadecimal number between the braces.
The output record separator for the print operator. If defined, this value is printed after the last of print’s arguments. Well behaved code should ensure that when setting up a require__before hook that any prior installed hook will be called, and that their return value, if a code reference, will be called as well. See “require” in perlfunc for an example implementation. Require__before hooks are called in FIFO order, and if the hook returns a code reference those code references will be called in FILO order. In other words if A requires B requires C, then require__before will be called first for A, then B and then C, and the post-action code reference will be executed first for C, then B and then finally A.
#Operator Precedence and Associativity
A /e will cause the replacement portion to be treated as a full-fledged Perl expression and evaluated right then and there. A second e modifier will cause the replacement portion to be evaled before being run as a Perl expression. They include variables, quote and quote-like operators, any expression in parentheses, and any function whose arguments are parenthesized. Actually, there aren’t really functions in this sense, just list operators and unary operators behaving as functions because you put parentheses around the arguments.
