{
    "mode": "perldoc",
    "parameter": "perlop",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/perlop/json",
    "generated": "2026-06-03T04:26:16Z",
    "sections": {
        "NAME": {
            "content": "perlop - Perl operators and precedence\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "In Perl, the operator determines what operation is performed, independent of the type of the\noperands. For example \"$x + $y\" is always a numeric addition, and if $x or $y do not contain\nnumbers, an attempt is made to convert them to numbers first.\n\nThis is in contrast to many other dynamic languages, where the operation is determined by the\ntype of the first argument. It also means that Perl has two versions of some operators, one for\nnumeric and one for string comparison. For example \"$x == $y\" compares two numbers for equality,\nand \"$x eq $y\" compares two strings.\n\nThere are a few exceptions though: \"x\" can be either string repetition or list repetition,\ndepending on the type of the left operand, and \"&\", \"|\", \"^\" and \"~\" can be either string or\nnumeric bit operations.\n",
            "subsections": [
                {
                    "name": "Operator Precedence and Associativity",
                    "content": "Operator precedence and associativity work in Perl more or less like they do in mathematics.\n\n*Operator precedence* means some operators group more tightly than others. For example, in \"2 +\n4 * 5\", the multiplication has higher precedence, so \"4 * 5\" is grouped together as the\nright-hand operand of the addition, rather than \"2 + 4\" being grouped together as the left-hand\noperand of the multiplication. It is as if the expression were written \"2 + (4 * 5)\", not \"(2 +\n4) * 5\". So the expression yields \"2 + 20 == 22\", rather than \"6 * 5 == 30\".\n\n*Operator associativity* defines what happens if a sequence of the same operators is used one\nafter another: usually that they will be grouped at the left or the right. For example, in \"9 -\n3 - 2\", subtraction is left associative, so \"9 - 3\" is grouped together as the left-hand operand\nof the second subtraction, rather than \"3 - 2\" being grouped together as the right-hand operand\nof the first subtraction. It is as if the expression were written \"(9 - 3) - 2\", not \"9 - (3 -\n2)\". So the expression yields \"6 - 2 == 4\", rather than \"9 - 1 == 8\".\n\nFor simple operators that evaluate all their operands and then combine the values in some way,\nprecedence and associativity (and parentheses) imply some ordering requirements on those\ncombining operations. For example, in \"2 + 4 * 5\", the grouping implied by precedence means that\nthe multiplication of 4 and 5 must be performed before the addition of 2 and 20, simply because\nthe result of that multiplication is required as one of the operands of the addition. But the\norder of operations is not fully determined by this: in \"2 * 2 + 4 * 5\" both multiplications\nmust be performed before the addition, but the grouping does not say anything about the order in\nwhich the two multiplications are performed. In fact Perl has a general rule that the operands\nof an operator are evaluated in left-to-right order. A few operators such as \"&&=\" have special\nevaluation rules that can result in an operand not being evaluated at all; in general, the\ntop-level operator in an expression has control of operand evaluation.\n\nSome comparison operators, as their associativity, *chain* with some operators of the same\nprecedence (but never with operators of different precedence). This chaining means that each\ncomparison is performed on the two arguments surrounding it, with each interior argument taking\npart in two comparisons, and the comparison results are implicitly ANDed. Thus \"$x < $y <= $z\"\nbehaves exactly like \"$x < $y && $y <= $z\", assuming that \"$y\" is as simple a scalar as it\nlooks. The ANDing short-circuits just like \"&&\" does, stopping the sequence of comparisons as\nsoon as one yields false.\n\nIn a chained comparison, each argument expression is evaluated at most once, even if it takes\npart in two comparisons, but the result of the evaluation is fetched for each comparison. (It is\nnot evaluated at all if the short-circuiting means that it's not required for any comparisons.)\nThis matters if the computation of an interior argument is expensive or non-deterministic. For\nexample,\n\nif($x < expensivesub() <= $z) { ...\n\nis not entirely like\n\nif($x < expensivesub() && expensivesub() <= $z) { ...\n\nbut instead closer to\n\nmy $tmp = expensivesub();\nif($x < $tmp && $tmp <= $z) { ...\n\nin that the subroutine is only called once. However, it's not exactly like this latter code\neither, because the chained comparison doesn't actually involve any temporary variable (named or\notherwise): there is no assignment. This doesn't make much difference where the expression is a\ncall to an ordinary subroutine, but matters more with an lvalue subroutine, or if the argument\nexpression yields some unusual kind of scalar by other means. For example, if the argument\nexpression yields a tied scalar, then the expression is evaluated to produce that scalar at most\nonce, but the value of that scalar may be fetched up to twice, once for each comparison in which\nit is actually used.\n\nIn this example, the expression is evaluated only once, and the tied scalar (the result of the\nexpression) is fetched for each comparison that uses it.\n\nif ($x < $tiedscalar < $z) { ...\n\nIn the next example, the expression is evaluated only once, and the tied scalar is fetched once\nas part of the operation within the expression. The result of that operation is fetched for each\ncomparison, which normally doesn't matter unless that expression result is also magical due to\noperator overloading.\n\nif ($x < $tiedscalar + 42 < $z) { ...\n\nSome operators are instead non-associative, meaning that it is a syntax error to use a sequence\nof those operators of the same precedence. For example, \"$x .. $y .. $z\" is an error.\n\nPerl operators have the following associativity and precedence, listed from highest precedence\nto lowest. Operators borrowed from C keep the same precedence relationship with each other, even\nwhere C's precedence is slightly screwy. (This makes learning Perl easier for C folks.) With\nvery few exceptions, these all operate on scalar values only, not array values.\n\nleft        terms and list operators (leftward)\nleft        ->\nnonassoc    ++ --\nright\nright       ! ~ ~. \\ and unary + and -\nleft        =~ !~\nleft        * / % x\nleft        + - .\nleft        << >>\nnonassoc    named unary operators\nnonassoc    isa\nchained     < > <= >= lt gt le ge\nchain/na    == != eq ne <=> cmp ~~\nleft        & &.\nleft        | |. ^ ^.\nleft        &&\nleft        || //\nnonassoc    ..  ...\nright       ?:\nright       = += -= *= etc. goto last next redo dump\nleft        , =>\nnonassoc    list operators (rightward)\nright       not\nleft        and\nleft        or xor\n\nIn the following sections, these operators are covered in detail, in the same order in which\nthey appear in the table above.\n\nMany operators can be overloaded for objects. See overload.\n\nTerms and List Operators (Leftward)\nA TERM has the highest precedence in Perl. They include variables, quote and quote-like\noperators, any expression in parentheses, and any function whose arguments are parenthesized.\nActually, there aren't really functions in this sense, just list operators and unary operators\nbehaving as functions because you put parentheses around the arguments. These are all documented\nin perlfunc.\n\nIf any list operator (\"print()\", etc.) or any unary operator (\"chdir()\", etc.) is followed by a\nleft parenthesis as the next token, the operator and arguments within parentheses are taken to\nbe of highest precedence, just like a normal function call.\n\nIn the absence of parentheses, the precedence of list operators such as \"print\", \"sort\", or\n\"chmod\" is either very high or very low depending on whether you are looking at the left side or\nthe right side of the operator. For example, in\n\n@ary = (1, 3, sort 4, 2);\nprint @ary;         # prints 1324\n\nthe commas on the right of the \"sort\" are evaluated before the \"sort\", but the commas on the\nleft are evaluated after. In other words, list operators tend to gobble up all arguments that\nfollow, and then act like a simple TERM with regard to the preceding expression. Be careful with\nparentheses:\n\n# These evaluate exit before doing the print:\nprint($foo, exit);  # Obviously not what you want.\nprint $foo, exit;   # Nor is this.\n\n# These do the print before evaluating exit:\n(print $foo), exit; # This is what you want.\nprint($foo), exit;  # Or this.\nprint ($foo), exit; # Or even this.\n\nAlso note that\n\nprint ($foo & 255) + 1, \"\\n\";\n\nprobably doesn't do what you expect at first glance. The parentheses enclose the argument list\nfor \"print\" which is evaluated (printing the result of \"$foo & 255\"). Then one is added to the\nreturn value of \"print\" (usually 1). The result is something like this:\n\n1 + 1, \"\\n\";    # Obviously not what you meant.\n\nTo do what you meant properly, you must write:\n\nprint(($foo & 255) + 1, \"\\n\");\n\nSee \"Named Unary Operators\" for more discussion of this.\n\nAlso parsed as terms are the \"do {}\" and \"eval {}\" constructs, as well as subroutine and method\ncalls, and the anonymous constructors \"[]\" and \"{}\".\n\nSee also \"Quote and Quote-like Operators\" toward the end of this section, as well as \"I/O\nOperators\".\n"
                },
                {
                    "name": "The Arrow Operator",
                    "content": "\"\"->\"\" is an infix dereference operator, just as it is in C and C++. If the right side is either\na \"[...]\", \"{...}\", or a \"(...)\" subscript, then the left side must be either a hard or symbolic\nreference to an array, a hash, or a subroutine respectively. (Or technically speaking, a\nlocation capable of holding a hard reference, if it's an array or hash reference being used for\nassignment.) See perlreftut and perlref.\n\nOtherwise, the right side is a method name or a simple scalar variable containing either the\nmethod name or a subroutine reference, and the left side must be either an object (a blessed\nreference) or a class name (that is, a package name). See perlobj.\n\nThe dereferencing cases (as opposed to method-calling cases) are somewhat extended by the\n\"postderef\" feature. For the details of that feature, consult \"Postfix Dereference Syntax\" in\nperlref.\n"
                },
                {
                    "name": "Auto-increment and Auto-decrement",
                    "content": "\"++\" and \"--\" work as in C. That is, if placed before a variable, they increment or decrement\nthe variable by one before returning the value, and if placed after, increment or decrement\nafter returning the value.\n\n$i = 0;  $j = 0;\nprint $i++;  # prints 0\nprint ++$j;  # prints 1\n\nNote that just as in C, Perl doesn't define when the variable is incremented or decremented. You\njust know it will be done sometime before or after the value is returned. This also means that\nmodifying a variable twice in the same statement will lead to undefined behavior. Avoid\nstatements like:\n\n$i = $i ++;\nprint ++ $i + $i ++;\n\nPerl will not guarantee what the result of the above statements is.\n\nThe auto-increment operator has a little extra builtin magic to it. If you increment a variable\nthat is numeric, or that has ever been used in a numeric context, you get a normal increment.\nIf, however, the variable has been used in only string contexts since it was set, and has a\nvalue that is not the empty string and matches the pattern \"/^[a-zA-Z]*[0-9]*\\z/\", the increment\nis done as a string, preserving each character within its range, with carry:\n\nprint ++($foo = \"99\");      # prints \"100\"\nprint ++($foo = \"a0\");      # prints \"a1\"\nprint ++($foo = \"Az\");      # prints \"Ba\"\nprint ++($foo = \"zz\");      # prints \"aaa\"\n\n\"undef\" is always treated as numeric, and in particular is changed to 0 before incrementing (so\nthat a post-increment of an undef value will return 0 rather than \"undef\").\n\nThe auto-decrement operator is not magical.\n"
                },
                {
                    "name": "Exponentiation",
                    "content": "Binary \"\" is the exponentiation operator. It binds even more tightly than unary minus, so\n\"-24\" is \"-(24)\", not \"(-2)4\". (This is implemented using C's pow(3) function, which\nactually works on doubles internally.)\n\nNote that certain exponentiation expressions are ill-defined: these include \"00\", \"1Inf\",\nand \"Inf0\". Do not expect any particular results from these special cases, the results are\nplatform-dependent.\n"
                },
                {
                    "name": "Symbolic Unary Operators",
                    "content": "Unary \"!\" performs logical negation, that is, \"not\". See also \"not\" for a lower precedence\nversion of this.\n\nUnary \"-\" performs arithmetic negation if the operand is numeric, including any string that\nlooks like a number. If the operand is an identifier, a string consisting of a minus sign\nconcatenated with the identifier is returned. Otherwise, if the string starts with a plus or\nminus, a string starting with the opposite sign is returned. One effect of these rules is that\n\"-bareword\" is equivalent to the string \"-bareword\". If, however, the string begins with a\nnon-alphabetic character (excluding \"+\" or \"-\"), Perl will attempt to convert the string to a\nnumeric, and the arithmetic negation is performed. If the string cannot be cleanly converted to\na numeric, Perl will give the warning Argument \"the string\" isn't numeric in negation (-) at\n....\n\nUnary \"~\" performs bitwise negation, that is, 1's complement. For example, \"0666 & ~027\" is\n0640. (See also \"Integer Arithmetic\" and \"Bitwise String Operators\".) Note that the width of the\nresult is platform-dependent: \"~0\" is 32 bits wide on a 32-bit platform, but 64 bits wide on a\n64-bit platform, so if you are expecting a certain bit width, remember to use the \"&\" operator\nto mask off the excess bits.\n\nStarting in Perl 5.28, it is a fatal error to try to complement a string containing a character\nwith an ordinal value above 255.\n\nIf the \"bitwise\" feature is enabled via \"use feature 'bitwise'\" or \"use v5.28\", then unary \"~\"\nalways treats its argument as a number, and an alternate form of the operator, \"~.\", always\ntreats its argument as a string. So \"~0\" and \"~\"0\"\" will both give 232-1 on 32-bit platforms,\nwhereas \"~.0\" and \"~.\"0\"\" will both yield \"\\xff\". Until Perl 5.28, this feature produced a\nwarning in the \"experimental::bitwise\" category.\n\nUnary \"+\" has no effect whatsoever, even on strings. It is useful syntactically for separating a\nfunction name from a parenthesized expression that would otherwise be interpreted as the\ncomplete list of function arguments. (See examples above under \"Terms and List Operators\n(Leftward)\".)\n\nUnary \"\\\" creates references. If its operand is a single sigilled thing, it creates a reference\nto that object. If its operand is a parenthesised list, then it creates references to the things\nmentioned in the list. Otherwise it puts its operand in list context, and creates a list of\nreferences to the scalars in the list provided by the operand. See perlreftut and perlref. Do\nnot confuse this behavior with the behavior of backslash within a string, although both forms do\nconvey the notion of protecting the next thing from interpolation.\n"
                },
                {
                    "name": "Binding Operators",
                    "content": "Binary \"=~\" binds a scalar expression to a pattern match. Certain operations search or modify\nthe string $ by default. This operator makes that kind of operation work on some other string.\nThe right argument is a search pattern, substitution, or transliteration. The left argument is\nwhat is supposed to be searched, substituted, or transliterated instead of the default $. When\nused in scalar context, the return value generally indicates the success of the operation. The\nexceptions are substitution (\"s///\") and transliteration (\"y///\") with the \"/r\"\n(non-destructive) option, which cause the return value to be the result of the substitution.\nBehavior in list context depends on the particular operator. See \"Regexp Quote-Like Operators\"\nfor details and perlretut for examples using these operators.\n\nIf the right argument is an expression rather than a search pattern, substitution, or\ntransliteration, it is interpreted as a search pattern at run time. Note that this means that\nits contents will be interpolated twice, so\n\n'\\\\' =~ q'\\\\';\n\nis not ok, as the regex engine will end up trying to compile the pattern \"\\\", which it will\nconsider a syntax error.\n\nBinary \"!~\" is just like \"=~\" except the return value is negated in the logical sense.\n\nBinary \"!~\" with a non-destructive substitution (\"s///r\") or transliteration (\"y///r\") is a\nsyntax error.\n"
                },
                {
                    "name": "Multiplicative Operators",
                    "content": "Binary \"*\" multiplies two numbers.\n\nBinary \"/\" divides two numbers.\n\nBinary \"%\" is the modulo operator, which computes the division remainder of its first argument\nwith respect to its second argument. Given integer operands $m and $n: If $n is positive, then\n\"$m % $n\" is $m minus the largest multiple of $n less than or equal to $m. If $n is negative,\nthen \"$m % $n\" is $m minus the smallest multiple of $n that is not less than $m (that is, the\nresult will be less than or equal to zero). If the operands $m and $n are floating point values\nand the absolute value of $n (that is \"abs($n)\") is less than \"(UVMAX + 1)\", only the integer\nportion of $m and $n will be used in the operation (Note: here \"UVMAX\" means the maximum of the\nunsigned integer type). If the absolute value of the right operand (\"abs($n)\") is greater than\nor equal to \"(UVMAX + 1)\", \"%\" computes the floating-point remainder $r in the equation\n\"($r = $m - $i*$n)\" where $i is a certain integer that makes $r have the same sign as the right\noperand $n (not as the left operand $m like C function \"fmod()\") and the absolute value less\nthan that of $n. Note that when \"use integer\" is in scope, \"%\" gives you direct access to the\nmodulo operator as implemented by your C compiler. This operator is not as well defined for\nnegative operands, but it will execute faster.\n\nBinary \"x\" is the repetition operator. In scalar context, or if the left operand is neither\nenclosed in parentheses nor a \"qw//\" list, it performs a string repetition. In that case it\nsupplies scalar context to the left operand, and returns a string consisting of the left operand\nstring repeated the number of times specified by the right operand. If the \"x\" is in list\ncontext, and the left operand is either enclosed in parentheses or a \"qw//\" list, it performs a\nlist repetition. In that case it supplies list context to the left operand, and returns a list\nconsisting of the left operand list repeated the number of times specified by the right operand.\nIf the right operand is zero or negative (raising a warning on negative), it returns an empty\nstring or an empty list, depending on the context.\n\nprint '-' x 80;             # print row of dashes\n\nprint \"\\t\" x ($tab/8), ' ' x ($tab%8);      # tab over\n\n@ones = (1) x 80;           # a list of 80 1's\n@ones = (5) x @ones;        # set all elements to 5\n"
                },
                {
                    "name": "Additive Operators",
                    "content": "Binary \"+\" returns the sum of two numbers.\n\nBinary \"-\" returns the difference of two numbers.\n\nBinary \".\" concatenates two strings.\n"
                },
                {
                    "name": "Shift Operators",
                    "content": "Binary \"<<\" returns the value of its left argument shifted left by the number of bits specified\nby the right argument. Arguments should be integers. (See also \"Integer Arithmetic\".)\n\nBinary \">>\" returns the value of its left argument shifted right by the number of bits specified\nby the right argument. Arguments should be integers. (See also \"Integer Arithmetic\".)\n\nIf \"use integer\" (see \"Integer Arithmetic\") is in force then signed C integers are used\n(*arithmetic shift*), otherwise unsigned C integers are used (*logical shift*), even for\nnegative shiftees. In arithmetic right shift the sign bit is replicated on the left, in logical\nshift zero bits come in from the left.\n\nEither way, the implementation isn't going to generate results larger than the size of the\ninteger type Perl was built with (32 bits or 64 bits).\n\nShifting by negative number of bits means the reverse shift: left shift becomes right shift,\nright shift becomes left shift. This is unlike in C, where negative shift is undefined.\n\nShifting by more bits than the size of the integers means most of the time zero (all bits fall\noff), except that under \"use integer\" right overshifting a negative shiftee results in -1. This\nis unlike in C, where shifting by too many bits is undefined. A common C behavior is \"shift by\nmodulo wordbits\", so that for example\n\n1 >> 64 == 1 >> (64 % 64) == 1 >> 0 == 1  # Common C behavior.\n\nbut that is completely accidental.\n\nIf you get tired of being subject to your platform's native integers, the \"use bigint\" pragma\nneatly sidesteps the issue altogether:\n\nprint 20 << 20;  # 20971520\nprint 20 << 40;  # 5120 on 32-bit machines,\n# 21990232555520 on 64-bit machines\nuse bigint;\nprint 20 << 100; # 25353012004564588029934064107520\n"
                },
                {
                    "name": "Named Unary Operators",
                    "content": "The various named unary operators are treated as functions with one argument, with optional\nparentheses.\n\nIf any list operator (\"print()\", etc.) or any unary operator (\"chdir()\", etc.) is followed by a\nleft parenthesis as the next token, the operator and arguments within parentheses are taken to\nbe of highest precedence, just like a normal function call. For example, because named unary\noperators are higher precedence than \"||\":\n\nchdir $foo    || die;       # (chdir $foo) || die\nchdir($foo)   || die;       # (chdir $foo) || die\nchdir ($foo)  || die;       # (chdir $foo) || die\nchdir +($foo) || die;       # (chdir $foo) || die\n\nbut, because \"*\" is higher precedence than named operators:\n\nchdir $foo * 20;    # chdir ($foo * 20)\nchdir($foo) * 20;   # (chdir $foo) * 20\nchdir ($foo) * 20;  # (chdir $foo) * 20\nchdir +($foo) * 20; # chdir ($foo * 20)\n\nrand 10 * 20;       # rand (10 * 20)\nrand(10) * 20;      # (rand 10) * 20\nrand (10) * 20;     # (rand 10) * 20\nrand +(10) * 20;    # rand (10 * 20)\n\nRegarding precedence, the filetest operators, like \"-f\", \"-M\", etc. are treated like named unary\noperators, but they don't follow this functional parenthesis rule. That means, for example, that\n\"-f($file).\".bak\"\" is equivalent to \"-f \"$file.bak\"\".\n\nSee also \"Terms and List Operators (Leftward)\".\n"
                },
                {
                    "name": "Relational Operators",
                    "content": "Perl operators that return true or false generally return values that can be safely used as\nnumbers. For example, the relational operators in this section and the equality operators in the\nnext one return 1 for true and a special version of the defined empty string, \"\", which counts\nas a zero but is exempt from warnings about improper numeric conversions, just as \"0 but true\"\nis.\n\nBinary \"<\" returns true if the left argument is numerically less than the right argument.\n\nBinary \">\" returns true if the left argument is numerically greater than the right argument.\n\nBinary \"<=\" returns true if the left argument is numerically less than or equal to the right\nargument.\n\nBinary \">=\" returns true if the left argument is numerically greater than or equal to the right\nargument.\n\nBinary \"lt\" returns true if the left argument is stringwise less than the right argument.\n\nBinary \"gt\" returns true if the left argument is stringwise greater than the right argument.\n\nBinary \"le\" returns true if the left argument is stringwise less than or equal to the right\nargument.\n\nBinary \"ge\" returns true if the left argument is stringwise greater than or equal to the right\nargument.\n\nA sequence of relational operators, such as \"$x < $y <= $z\", performs chained comparisons, in\nthe manner described above in the section \"Operator Precedence and Associativity\". Beware that\nthey do not chain with equality operators, which have lower precedence.\n"
                },
                {
                    "name": "Equality Operators",
                    "content": "Binary \"==\" returns true if the left argument is numerically equal to the right argument.\n\nBinary \"!=\" returns true if the left argument is numerically not equal to the right argument.\n\nBinary \"eq\" returns true if the left argument is stringwise equal to the right argument.\n\nBinary \"ne\" returns true if the left argument is stringwise not equal to the right argument.\n\nA sequence of the above equality operators, such as \"$x == $y == $z\", performs chained\ncomparisons, in the manner described above in the section \"Operator Precedence and\nAssociativity\". Beware that they do not chain with relational operators, which have higher\nprecedence.\n\nBinary \"<=>\" returns -1, 0, or 1 depending on whether the left argument is numerically less\nthan, equal to, or greater than the right argument. If your platform supports \"NaN\"'s\n(not-a-numbers) as numeric values, using them with \"<=>\" returns undef. \"NaN\" is not \"<\", \"==\",\n\">\", \"<=\" or \">=\" anything (even \"NaN\"), so those 5 return false. \"NaN != NaN\" returns true, as\ndoes \"NaN !=\" *anything else*. If your platform doesn't support \"NaN\"'s then \"NaN\" is just a\nstring with numeric value 0.\n\n$ perl -le '$x = \"NaN\"; print \"No NaN support here\" if $x == $x'\n$ perl -le '$x = \"NaN\"; print \"NaN support here\" if $x != $x'\n\n(Note that the bigint, bigrat, and bignum pragmas all support \"NaN\".)\n\nBinary \"cmp\" returns -1, 0, or 1 depending on whether the left argument is stringwise less than,\nequal to, or greater than the right argument.\n\nBinary \"~~\" does a smartmatch between its arguments. Smart matching is described in the next\nsection.\n\nThe two-sided ordering operators \"<=>\" and \"cmp\", and the smartmatch operator \"~~\", are\nnon-associative with respect to each other and with respect to the equality operators of the\nsame precedence.\n\n\"lt\", \"le\", \"ge\", \"gt\" and \"cmp\" use the collation (sort) order specified by the current\n\"LCCOLLATE\" locale if a \"use locale\" form that includes collation is in effect. See perllocale.\nDo not mix these with Unicode, only use them with legacy 8-bit locale encodings. The standard\n\"Unicode::Collate\" and \"Unicode::Collate::Locale\" modules offer much more powerful solutions to\ncollation issues.\n\nFor case-insensitive comparisons, look at the \"fc\" in perlfunc case-folding function, available\nin Perl v5.16 or later:\n\nif ( fc($x) eq fc($y) ) { ... }\n"
                },
                {
                    "name": "Class Instance Operator",
                    "content": "Binary \"isa\" evaluates to true when the left argument is an object instance of the class (or a\nsubclass derived from that class) given by the right argument. If the left argument is not\ndefined, not a blessed object instance, nor does not derive from the class given by the right\nargument, the operator evaluates as false. The right argument may give the class either as a\nbareword or a scalar expression that yields a string class name:\n\nif( $obj isa Some::Class ) { ... }\n\nif( $obj isa \"Different::Class\" ) { ... }\nif( $obj isa $nameofclass ) { ... }\n\nThis is an experimental feature and is available from Perl 5.31.6 when enabled by \"use feature\n'isa'\". It emits a warning in the \"experimental::isa\" category.\n"
                },
                {
                    "name": "Smartmatch Operator",
                    "content": "First available in Perl 5.10.1 (the 5.10.0 version behaved differently), binary \"~~\" does a\n\"smartmatch\" between its arguments. This is mostly used implicitly in the \"when\" construct\ndescribed in perlsyn, although not all \"when\" clauses call the smartmatch operator. Unique among\nall of Perl's operators, the smartmatch operator can recurse. The smartmatch operator is\nexperimental and its behavior is subject to change.\n\nIt is also unique in that all other Perl operators impose a context (usually string or numeric\ncontext) on their operands, autoconverting those operands to those imposed contexts. In\ncontrast, smartmatch *infers* contexts from the actual types of its operands and uses that type\ninformation to select a suitable comparison mechanism.\n\nThe \"~~\" operator compares its operands \"polymorphically\", determining how to compare them\naccording to their actual types (numeric, string, array, hash, etc.). Like the equality\noperators with which it shares the same precedence, \"~~\" returns 1 for true and \"\" for false. It\nis often best read aloud as \"in\", \"inside of\", or \"is contained in\", because the left operand is\noften looked for *inside* the right operand. That makes the order of the operands to the\nsmartmatch operand often opposite that of the regular match operator. In other words, the\n\"smaller\" thing is usually placed in the left operand and the larger one in the right.\n\nThe behavior of a smartmatch depends on what type of things its arguments are, as determined by\nthe following table. The first row of the table whose types apply determines the smartmatch\nbehavior. Because what actually happens is mostly determined by the type of the second operand,\nthe table is sorted on the right operand instead of on the left.\n\nLeft      Right      Description and pseudocode\n===============================================================\nAny       undef      check whether Any is undefined\nlike: !defined Any\n\nAny       Object     invoke ~~ overloading on Object, or die\n\nRight operand is an ARRAY:\n\nLeft      Right      Description and pseudocode\n===============================================================\nARRAY1    ARRAY2     recurse on paired elements of ARRAY1 and ARRAY2[2]\nlike: (ARRAY1[0] ~~ ARRAY2[0])\n&& (ARRAY1[1] ~~ ARRAY2[1]) && ...\nHASH      ARRAY      any ARRAY elements exist as HASH keys\nlike: grep { exists HASH->{$} } ARRAY\nRegexp    ARRAY      any ARRAY elements pattern match Regexp\nlike: grep { /Regexp/ } ARRAY\nundef     ARRAY      undef in ARRAY\nlike: grep { !defined } ARRAY\nAny       ARRAY      smartmatch each ARRAY element[3]\nlike: grep { Any ~~ $ } ARRAY\n\nRight operand is a HASH:\n\nLeft      Right      Description and pseudocode\n===============================================================\nHASH1     HASH2      all same keys in both HASHes\nlike: keys HASH1 ==\ngrep { exists HASH2->{$} } keys HASH1\nARRAY     HASH       any ARRAY elements exist as HASH keys\nlike: grep { exists HASH->{$} } ARRAY\nRegexp    HASH       any HASH keys pattern match Regexp\nlike: grep { /Regexp/ } keys HASH\nundef     HASH       always false (undef can't be a key)\nlike: 0 == 1\nAny       HASH       HASH key existence\nlike: exists HASH->{Any}\n\nRight operand is CODE:\n\nLeft      Right      Description and pseudocode\n===============================================================\nARRAY     CODE       sub returns true on all ARRAY elements[1]\nlike: !grep { !CODE->($) } ARRAY\nHASH      CODE       sub returns true on all HASH keys[1]\nlike: !grep { !CODE->($) } keys HASH\nAny       CODE       sub passed Any returns true\nlike: CODE->(Any)\n\nRight operand is a Regexp:\n\nLeft      Right      Description and pseudocode\n===============================================================\nARRAY     Regexp     any ARRAY elements match Regexp\nlike: grep { /Regexp/ } ARRAY\nHASH      Regexp     any HASH keys match Regexp\nlike: grep { /Regexp/ } keys HASH\nAny       Regexp     pattern match\nlike: Any =~ /Regexp/\n\nOther:\n\nLeft      Right      Description and pseudocode\n===============================================================\nObject    Any        invoke ~~ overloading on Object,\nor fall back to...\n\nAny       Num        numeric equality\nlike: Any == Num\nNum       nummy[4]    numeric equality\nlike: Num == nummy\nundef     Any        check whether undefined\nlike: !defined(Any)\nAny       Any        string equality\nlike: Any eq Any\n\nNotes:\n\n1. Empty hashes or arrays match.\n2. That is, each element smartmatches the element of the same index in the other array.[3]\n3. If a circular reference is found, fall back to referential equality.\n4. Either an actual number, or a string that looks like one.\n\nThe smartmatch implicitly dereferences any non-blessed hash or array reference, so the \"*HASH*\"\nand \"*ARRAY*\" entries apply in those cases. For blessed references, the \"*Object*\" entries\napply. Smartmatches involving hashes only consider hash keys, never hash values.\n\nThe \"like\" code entry is not always an exact rendition. For example, the smartmatch operator\nshort-circuits whenever possible, but \"grep\" does not. Also, \"grep\" in scalar context returns\nthe number of matches, but \"~~\" returns only true or false.\n\nUnlike most operators, the smartmatch operator knows to treat \"undef\" specially:\n\nuse v5.10.1;\n@array = (1, 2, 3, undef, 4, 5);\nsay \"some elements undefined\" if undef ~~ @array;\n\nEach operand is considered in a modified scalar context, the modification being that array and\nhash variables are passed by reference to the operator, which implicitly dereferences them. Both\nelements of each pair are the same:\n\nuse v5.10.1;\n\nmy %hash = (red    => 1, blue   => 2, green  => 3,\norange => 4, yellow => 5, purple => 6,\nblack  => 7, grey   => 8, white  => 9);\n\nmy @array = qw(red blue green);\n\nsay \"some array elements in hash keys\" if  @array ~~  %hash;\nsay \"some array elements in hash keys\" if \\@array ~~ \\%hash;\n\nsay \"red in array\" if \"red\" ~~  @array;\nsay \"red in array\" if \"red\" ~~ \\@array;\n\nsay \"some keys end in e\" if /e$/ ~~  %hash;\nsay \"some keys end in e\" if /e$/ ~~ \\%hash;\n\nTwo arrays smartmatch if each element in the first array smartmatches (that is, is \"in\") the\ncorresponding element in the second array, recursively.\n\nuse v5.10.1;\nmy @little = qw(red blue green);\nmy @bigger = (\"red\", \"blue\", [ \"orange\", \"green\" ] );\nif (@little ~~ @bigger) {  # true!\nsay \"little is contained in bigger\";\n}\n\nBecause the smartmatch operator recurses on nested arrays, this will still report that \"red\" is\nin the array.\n\nuse v5.10.1;\nmy @array = qw(red blue green);\nmy $nestedarray = [[[[[[[ @array ]]]]]]];\nsay \"red in array\" if \"red\" ~~ $nestedarray;\n\nIf two arrays smartmatch each other, then they are deep copies of each others' values, as this\nexample reports:\n\nuse v5.12.0;\nmy @a = (0, 1, 2, [3, [4, 5], 6], 7);\nmy @b = (0, 1, 2, [3, [4, 5], 6], 7);\n\nif (@a ~~ @b && @b ~~ @a) {\nsay \"a and b are deep copies of each other\";\n}\nelsif (@a ~~ @b) {\nsay \"a smartmatches in b\";\n}\nelsif (@b ~~ @a) {\nsay \"b smartmatches in a\";\n}\nelse {\nsay \"a and b don't smartmatch each other at all\";\n}\n\nIf you were to set \"$b[3] = 4\", then instead of reporting that \"a and b are deep copies of each\nother\", it now reports that \"b smartmatches in a\". That's because the corresponding position in\n@a contains an array that (eventually) has a 4 in it.\n\nSmartmatching one hash against another reports whether both contain the same keys, no more and\nno less. This could be used to see whether two records have the same field names, without caring\nwhat values those fields might have. For example:\n\nuse v5.10.1;\nsub makedogtag {\nstate $REQUIREDFIELDS = { name=>1, rank=>1, serialnum=>1 };\n\nmy ($class, $initfields) = @;\n\ndie \"Must supply (only) name, rank, and serial number\"\nunless $initfields ~~ $REQUIREDFIELDS;\n\n...\n}\n\nHowever, this only does what you mean if $initfields is indeed a hash reference. The condition\n\"$initfields ~~ $REQUIREDFIELDS\" also allows the strings \"name\", \"rank\", \"serialnum\" as well\nas any array reference that contains \"name\" or \"rank\" or \"serialnum\" anywhere to pass through.\n\nThe smartmatch operator is most often used as the implicit operator of a \"when\" clause. See the\nsection on \"Switch Statements\" in perlsyn.\n\nSmartmatching of Objects\nTo avoid relying on an object's underlying representation, if the smartmatch's right operand is\nan object that doesn't overload \"~~\", it raises the exception \"\"Smartmatching a non-overloaded\nobject breaks encapsulation\"\". That's because one has no business digging around to see whether\nsomething is \"in\" an object. These are all illegal on objects without a \"~~\" overload:\n\n%hash ~~ $object\n42 ~~ $object\n\"fred\" ~~ $object\n\nHowever, you can change the way an object is smartmatched by overloading the \"~~\" operator. This\nis allowed to extend the usual smartmatch semantics. For objects that do have an \"~~\" overload,\nsee overload.\n\nUsing an object as the left operand is allowed, although not very useful. Smartmatching rules\ntake precedence over overloading, so even if the object in the left operand has smartmatch\noverloading, this will be ignored. A left operand that is a non-overloaded object falls back on\na string or numeric comparison of whatever the \"ref\" operator returns. That means that\n\n$object ~~ X\n\ndoes *not* invoke the overload method with \"*X*\" as an argument. Instead the above table is\nconsulted as normal, and based on the type of \"*X*\", overloading may or may not be invoked. For\nsimple strings or numbers, \"in\" becomes equivalent to this:\n\n$object ~~ $number          ref($object) == $number\n$object ~~ $string          ref($object) eq $string\n\nFor example, this reports that the handle smells IOish (but please don't really do this!):\n\nuse IO::Handle;\nmy $fh = IO::Handle->new();\nif ($fh ~~ /\\bIO\\b/) {\nsay \"handle smells IOish\";\n}\n\nThat's because it treats $fh as a string like \"IO::Handle=GLOB(0x8039e0)\", then pattern matches\nagainst that.\n"
                },
                {
                    "name": "Bitwise And",
                    "content": "Binary \"&\" returns its operands ANDed together bit by bit. Although no warning is currently\nraised, the result is not well defined when this operation is performed on operands that aren't\neither numbers (see \"Integer Arithmetic\") nor bitstrings (see \"Bitwise String Operators\").\n\nNote that \"&\" has lower priority than relational operators, so for example the parentheses are\nessential in a test like\n\nprint \"Even\\n\" if ($x & 1) == 0;\n\nIf the \"bitwise\" feature is enabled via \"use feature 'bitwise'\" or \"use v5.28\", then this\noperator always treats its operands as numbers. Before Perl 5.28 this feature produced a warning\nin the \"experimental::bitwise\" category.\n"
                },
                {
                    "name": "Bitwise Or and Exclusive Or",
                    "content": "Binary \"|\" returns its operands ORed together bit by bit.\n\nBinary \"^\" returns its operands XORed together bit by bit.\n\nAlthough no warning is currently raised, the results are not well defined when these operations\nare performed on operands that aren't either numbers (see \"Integer Arithmetic\") nor bitstrings\n(see \"Bitwise String Operators\").\n\nNote that \"|\" and \"^\" have lower priority than relational operators, so for example the\nparentheses are essential in a test like\n\nprint \"false\\n\" if (8 | 2) != 10;\n\nIf the \"bitwise\" feature is enabled via \"use feature 'bitwise'\" or \"use v5.28\", then this\noperator always treats its operands as numbers. Before Perl 5.28. this feature produced a\nwarning in the \"experimental::bitwise\" category.\n\nC-style Logical And\nBinary \"&&\" performs a short-circuit logical AND operation. That is, if the left operand is\nfalse, the right operand is not even evaluated. Scalar or list context propagates down to the\nright operand if it is evaluated.\n\nC-style Logical Or\nBinary \"||\" performs a short-circuit logical OR operation. That is, if the left operand is true,\nthe right operand is not even evaluated. Scalar or list context propagates down to the right\noperand if it is evaluated.\n"
                },
                {
                    "name": "Logical Defined-Or",
                    "content": "Although it has no direct equivalent in C, Perl's \"//\" operator is related to its C-style \"or\".\nIn fact, it's exactly the same as \"||\", except that it tests the left hand side's definedness\ninstead of its truth. Thus, \"EXPR1 // EXPR2\" returns the value of \"EXPR1\" if it's defined,\notherwise, the value of \"EXPR2\" is returned. (\"EXPR1\" is evaluated in scalar context, \"EXPR2\" in\nthe context of \"//\" itself). Usually, this is the same result as\n\"defined(EXPR1) ? EXPR1 : EXPR2\" (except that the ternary-operator form can be used as a lvalue,\nwhile \"EXPR1 // EXPR2\" cannot). This is very useful for providing default values for variables.\nIf you actually want to test if at least one of $x and $y is defined, use \"defined($x // $y)\".\n\nThe \"||\", \"//\" and \"&&\" operators return the last value evaluated (unlike C's \"||\" and \"&&\",\nwhich return 0 or 1). Thus, a reasonably portable way to find out the home directory might be:\n\n$home =  $ENV{HOME}\n// $ENV{LOGDIR}\n// (getpwuid($<))[7]\n// die \"You're homeless!\\n\";\n\nIn particular, this means that you shouldn't use this for selecting between two aggregates for\nassignment:\n\n@a = @b || @c;            # This doesn't do the right thing\n@a = scalar(@b) || @c;    # because it really means this.\n@a = @b ? @b : @c;        # This works fine, though.\n\nAs alternatives to \"&&\" and \"||\" when used for control flow, Perl provides the \"and\" and \"or\"\noperators (see below). The short-circuit behavior is identical. The precedence of \"and\" and \"or\"\nis much lower, however, so that you can safely use them after a list operator without the need\nfor parentheses:\n\nunlink \"alpha\", \"beta\", \"gamma\"\nor gripe(), next LINE;\n\nWith the C-style operators that would have been written like this:\n\nunlink(\"alpha\", \"beta\", \"gamma\")\n|| (gripe(), next LINE);\n\nIt would be even more readable to write that this way:\n\nunless(unlink(\"alpha\", \"beta\", \"gamma\")) {\ngripe();\nnext LINE;\n}\n\nUsing \"or\" for assignment is unlikely to do what you want; see below.\n"
                },
                {
                    "name": "Range Operators",
                    "content": "Binary \"..\" is the range operator, which is really two different operators depending on the\ncontext. In list context, it returns a list of values counting (up by ones) from the left value\nto the right value. If the left value is greater than the right value then it returns the empty\nlist. The range operator is useful for writing \"foreach (1..10)\" loops and for doing slice\noperations on arrays. In the current implementation, no temporary array is created when the\nrange operator is used as the expression in \"foreach\" loops, but older versions of Perl might\nburn a lot of memory when you write something like this:\n\nfor (1 .. 1000000) {\n# code\n}\n\nThe range operator also works on strings, using the magical auto-increment, see below.\n\nIn scalar context, \"..\" returns a boolean value. The operator is bistable, like a flip-flop, and\nemulates the line-range (comma) operator of sed, awk, and various editors. Each \"..\" operator\nmaintains its own boolean state, even across calls to a subroutine that contains it. It is false\nas long as its left operand is false. Once the left operand is true, the range operator stays\ntrue until the right operand is true, *AFTER* which the range operator becomes false again. It\ndoesn't become false till the next time the range operator is evaluated. It can test the right\noperand and become false on the same evaluation it became true (as in awk), but it still returns\ntrue once. If you don't want it to test the right operand until the next evaluation, as in sed,\njust use three dots (\"...\") instead of two. In all other regards, \"...\" behaves just like \"..\"\ndoes.\n\nThe right operand is not evaluated while the operator is in the \"false\" state, and the left\noperand is not evaluated while the operator is in the \"true\" state. The precedence is a little\nlower than || and &&. The value returned is either the empty string for false, or a sequence\nnumber (beginning with 1) for true. The sequence number is reset for each range encountered. The\nfinal sequence number in a range has the string \"E0\" appended to it, which doesn't affect its\nnumeric value, but gives you something to search for if you want to exclude the endpoint. You\ncan exclude the beginning point by waiting for the sequence number to be greater than 1.\n\nIf either operand of scalar \"..\" is a constant expression, that operand is considered true if it\nis equal (\"==\") to the current input line number (the $. variable).\n\nTo be pedantic, the comparison is actually \"int(EXPR) == int(EXPR)\", but that is only an issue\nif you use a floating point expression; when implicitly using $. as described in the previous\nparagraph, the comparison is \"int(EXPR) == int($.)\" which is only an issue when $. is set to a\nfloating point value and you are not reading from a file. Furthermore, \"span\" .. \"spat\" or\n\"2.18 .. 3.14\" will not do what you want in scalar context because each of the operands are\nevaluated using their integer representation.\n\nExamples:\n\nAs a scalar operator:\n\nif (101 .. 200) { print; } # print 2nd hundred lines, short for\n#  if ($. == 101 .. $. == 200) { print; }\n\nnext LINE if (1 .. /^$/);  # skip header lines, short for\n#   next LINE if ($. == 1 .. /^$/);\n# (typically in a loop labeled LINE)\n\ns/^/> / if (/^$/ .. eof());  # quote body\n\n# parse mail messages\nwhile (<>) {\n$inheader =   1  .. /^$/;\n$inbody   = /^$/ .. eof;\nif ($inheader) {\n# do something\n} else { # in body\n# do something else\n}\n} continue {\nclose ARGV if eof;             # reset $. each file\n}\n\nHere's a simple example to illustrate the difference between the two range operators:\n\n@lines = (\"   - Foo\",\n\"01 - Bar\",\n\"1  - Baz\",\n\"   - Quux\");\n\nforeach (@lines) {\nif (/0/ .. /1/) {\nprint \"$\\n\";\n}\n}\n\nThis program will print only the line containing \"Bar\". If the range operator is changed to\n\"...\", it will also print the \"Baz\" line.\n\nAnd now some examples as a list operator:\n\nfor (101 .. 200) { print }      # print $ 100 times\n@foo = @foo[0 .. $#foo];        # an expensive no-op\n@foo = @foo[$#foo-4 .. $#foo];  # slice last 5 items\n\nBecause each operand is evaluated in integer form, \"2.18 .. 3.14\" will return two elements in\nlist context.\n\n@list = (2.18 .. 3.14); # same as @list = (2 .. 3);\n\nThe range operator in list context can make use of the magical auto-increment algorithm if both\noperands are strings, subject to the following rules:\n\n*   With one exception (below), if both strings look like numbers to Perl, the magic increment\nwill not be applied, and the strings will be treated as numbers (more specifically,\nintegers) instead.\n\nFor example, \"-2\"..\"2\" is the same as -2..2, and \"2.18\"..\"3.14\" produces \"2, 3\".\n\n*   The exception to the above rule is when the left-hand string begins with 0 and is longer\nthan one character, in this case the magic increment *will* be applied, even though strings\nlike \"01\" would normally look like a number to Perl.\n\nFor example, \"01\"..\"04\" produces \"01\", \"02\", \"03\", \"04\", and \"00\"..\"-1\" produces \"00\"\nthrough \"99\" - this may seem surprising, but see the following rules for why it works this\nway. To get dates with leading zeros, you can say:\n\n@z2 = (\"01\" .. \"31\");\nprint $z2[$mday];\n\nIf you want to force strings to be interpreted as numbers, you could say\n\n@numbers = ( 0+$first .. 0+$last );\n\nNote: In Perl versions 5.30 and below, *any* string on the left-hand side beginning with\n\"0\", including the string \"0\" itself, would cause the magic string increment behavior. This\nmeans that on these Perl versions, \"0\"..\"-1\" would produce \"0\" through \"99\", which was\ninconsistent with \"0..-1\", which produces the empty list. This also means that \"0\"..\"9\" now\nproduces a list of integers instead of a list of strings.\n\n*   If the initial value specified isn't part of a magical increment sequence (that is, a\nnon-empty string matching \"/^[a-zA-Z]*[0-9]*\\z/\"), only the initial value will be returned.\n\nFor example, \"ax\"..\"az\" produces \"ax\", \"ay\", \"az\", but \"*x\"..\"az\" produces only \"*x\".\n\n*   For other initial values that are strings that do follow the rules of the magical increment,\nthe corresponding sequence will be returned.\n\nFor example, you can say\n\n@alphabet = (\"A\" .. \"Z\");\n\nto get all normal letters of the English alphabet, or\n\n$hexdigit = (0 .. 9, \"a\" .. \"f\")[$num & 15];\n\nto get a hexadecimal digit.\n\n*   If the final value specified is not in the sequence that the magical increment would\nproduce, the sequence goes until the next value would be longer than the final value\nspecified. If the length of the final string is shorter than the first, the empty list is\nreturned.\n\nFor example, \"a\"..\"--\" is the same as \"a\"..\"zz\", \"0\"..\"xx\" produces \"0\" through \"99\", and\n\"aaa\"..\"--\" returns the empty list.\n\nAs of Perl 5.26, the list-context range operator on strings works as expected in the scope of\n\"use feature 'unicodestrings\". In previous versions, and outside the scope of that feature, it\nexhibits \"The \"Unicode Bug\"\" in perlunicode: its behavior depends on the internal encoding of\nthe range endpoint.\n\nBecause the magical increment only works on non-empty strings matching \"/^[a-zA-Z]*[0-9]*\\z/\",\nthe following will only return an alpha:\n\nuse charnames \"greek\";\nmy @greeksmall =  (\"\\N{alpha}\" .. \"\\N{omega}\");\n\nTo get the 25 traditional lowercase Greek letters, including both sigmas, you could use this\ninstead:\n\nuse charnames \"greek\";\nmy @greeksmall =  map { chr } ( ord(\"\\N{alpha}\")\n..\nord(\"\\N{omega}\")\n);\n\nHowever, because there are *many* other lowercase Greek characters than just those, to match\nlowercase Greek characters in a regular expression, you could use the pattern\n\"/(?:(?=\\p{Greek})\\p{Lower})+/\" (or the experimental feature \"/(?[ \\p{Greek} & \\p{Lower} ])+/\").\n"
                },
                {
                    "name": "Conditional Operator",
                    "content": "Ternary \"?:\" is the conditional operator, just as in C. It works much like an if-then-else. If\nthe argument before the \"?\" is true, the argument before the \":\" is returned, otherwise the\nargument after the \":\" is returned. For example:\n\nprintf \"I have %d dog%s.\\n\", $n,\n($n == 1) ? \"\" : \"s\";\n\nScalar or list context propagates downward into the 2nd or 3rd argument, whichever is selected.\n\n$x = $ok ? $y : $z;  # get a scalar\n@x = $ok ? @y : @z;  # get an array\n$x = $ok ? @y : @z;  # oops, that's just a count!\n\nThe operator may be assigned to if both the 2nd and 3rd arguments are legal lvalues (meaning\nthat you can assign to them):\n\n($xory ? $x : $y) = $z;\n\nBecause this operator produces an assignable result, using assignments without parentheses will\nget you in trouble. For example, this:\n\n$x % 2 ? $x += 10 : $x += 2\n\nReally means this:\n\n(($x % 2) ? ($x += 10) : $x) += 2\n\nRather than this:\n\n($x % 2) ? ($x += 10) : ($x += 2)\n\nThat should probably be written more simply as:\n\n$x += ($x % 2) ? 10 : 2;\n"
                },
                {
                    "name": "Assignment Operators",
                    "content": "\"=\" is the ordinary assignment operator.\n\nAssignment operators work as in C. That is,\n\n$x += 2;\n\nis equivalent to\n\n$x = $x + 2;\n\nalthough without duplicating any side effects that dereferencing the lvalue might trigger, such\nas from \"tie()\". Other assignment operators work similarly. The following are recognized:\n\n=    +=    *=    &=    &.=    <<=    &&=\n-=    /=    |=    |.=    >>=    ||=\n.=    %=    ^=    ^.=           //=\nx=\n\nAlthough these are grouped by family, they all have the precedence of assignment. These combined\nassignment operators can only operate on scalars, whereas the ordinary assignment operator can\nassign to arrays, hashes, lists and even references. (See \"Context\" and \"List value\nconstructors\" in perldata, and \"Assigning to References\" in perlref.)\n\nUnlike in C, the scalar assignment operator produces a valid lvalue. Modifying an assignment is\nequivalent to doing the assignment and then modifying the variable that was assigned to. This is\nuseful for modifying a copy of something, like this:\n\n($tmp = $global) =~ tr/13579/24680/;\n\nAlthough as of 5.14, that can be also be accomplished this way:\n\nuse v5.14;\n$tmp = ($global =~  tr/13579/24680/r);\n\nLikewise,\n\n($x += 2) *= 3;\n\nis equivalent to\n\n$x += 2;\n$x *= 3;\n\nSimilarly, a list assignment in list context produces the list of lvalues assigned to, and a\nlist assignment in scalar context returns the number of elements produced by the expression on\nthe right hand side of the assignment.\n\nThe three dotted bitwise assignment operators (\"&.=\" \"|.=\" \"^.=\") are new in Perl 5.22. See\n\"Bitwise String Operators\".\n"
                },
                {
                    "name": "Comma Operator",
                    "content": "Binary \",\" is the comma operator. In scalar context it evaluates its left argument, throws that\nvalue away, then evaluates its right argument and returns that value. This is just like C's\ncomma operator.\n\nIn list context, it's just the list argument separator, and inserts both its arguments into the\nlist. These arguments are also evaluated from left to right.\n\nThe \"=>\" operator (sometimes pronounced \"fat comma\") is a synonym for the comma except that it\ncauses a word on its left to be interpreted as a string if it begins with a letter or underscore\nand is composed only of letters, digits and underscores. This includes operands that might\notherwise be interpreted as operators, constants, single number v-strings or function calls. If\nin doubt about this behavior, the left operand can be quoted explicitly.\n\nOtherwise, the \"=>\" operator behaves exactly as the comma operator or list argument separator,\naccording to context.\n\nFor example:\n\nuse constant FOO => \"something\";\n\nmy %h = ( FOO => 23 );\n\nis equivalent to:\n\nmy %h = (\"FOO\", 23);\n\nIt is *NOT*:\n\nmy %h = (\"something\", 23);\n\nThe \"=>\" operator is helpful in documenting the correspondence between keys and values in\nhashes, and other paired elements in lists.\n\n%hash = ( $key => $value );\nlogin( $username => $password );\n\nThe special quoting behavior ignores precedence, and hence may apply to *part* of the left\noperand:\n\nprint time.shift => \"bbb\";\n\nThat example prints something like \"1314363215shiftbbb\", because the \"=>\" implicitly quotes the\n\"shift\" immediately on its left, ignoring the fact that \"time.shift\" is the entire left operand.\n\nList Operators (Rightward)\nOn the right side of a list operator, the comma has very low precedence, such that it controls\nall comma-separated expressions found there. The only operators with lower precedence are the\nlogical operators \"and\", \"or\", and \"not\", which may be used to evaluate calls to list operators\nwithout the need for parentheses:\n\nopen HANDLE, \"< :encoding(UTF-8)\", \"filename\"\nor die \"Can't open: $!\\n\";\n\nHowever, some people find that code harder to read than writing it with parentheses:\n\nopen(HANDLE, \"< :encoding(UTF-8)\", \"filename\")\nor die \"Can't open: $!\\n\";\n\nin which case you might as well just use the more customary \"||\" operator:\n\nopen(HANDLE, \"< :encoding(UTF-8)\", \"filename\")\n|| die \"Can't open: $!\\n\";\n\nSee also discussion of list operators in \"Terms and List Operators (Leftward)\".\n"
                },
                {
                    "name": "Logical Not",
                    "content": "Unary \"not\" returns the logical negation of the expression to its right. It's the equivalent of\n\"!\" except for the very low precedence.\n"
                },
                {
                    "name": "Logical And",
                    "content": "Binary \"and\" returns the logical conjunction of the two surrounding expressions. It's equivalent\nto \"&&\" except for the very low precedence. This means that it short-circuits: the right\nexpression is evaluated only if the left expression is true.\n"
                },
                {
                    "name": "Logical or and Exclusive Or",
                    "content": "Binary \"or\" returns the logical disjunction of the two surrounding expressions. It's equivalent\nto \"||\" except for the very low precedence. This makes it useful for control flow:\n\nprint FH $data              or die \"Can't write to FH: $!\";\n\nThis means that it short-circuits: the right expression is evaluated only if the left expression\nis false. Due to its precedence, you must be careful to avoid using it as replacement for the\n\"||\" operator. It usually works out better for flow control than in assignments:\n\n$x = $y or $z;              # bug: this is wrong\n($x = $y) or $z;            # really means this\n$x = $y || $z;              # better written this way\n\nHowever, when it's a list-context assignment and you're trying to use \"||\" for control flow, you\nprobably need \"or\" so that the assignment takes higher precedence.\n\n@info = stat($file) || die;     # oops, scalar sense of stat!\n@info = stat($file) or die;     # better, now @info gets its due\n\nThen again, you could always use parentheses.\n\nBinary \"xor\" returns the exclusive-OR of the two surrounding expressions. It cannot\nshort-circuit (of course).\n\nThere is no low precedence operator for defined-OR.\n\nC Operators Missing From Perl\nHere is what C has that Perl doesn't:\n\nunary & Address-of operator. (But see the \"\\\" operator for taking a reference.)\n\nunary * Dereference-address operator. (Perl's prefix dereferencing operators are typed: \"$\",\n\"@\", \"%\", and \"&\".)\n\n(TYPE)  Type-casting operator.\n"
                },
                {
                    "name": "Quote and Quote-like Operators",
                    "content": "While we usually think of quotes as literal values, in Perl they function as operators,\nproviding various kinds of interpolating and pattern matching capabilities. Perl provides\ncustomary quote characters for these behaviors, but also provides a way for you to choose your\nquote character for any of them. In the following table, a \"{}\" represents any pair of\ndelimiters you choose.\n\nCustomary  Generic        Meaning        Interpolates\n''       q{}          Literal             no\n\"\"      qq{}          Literal             yes\n``      qx{}          Command             yes*\nqw{}         Word list            no\n//       m{}       Pattern match          yes*\nqr{}          Pattern             yes*\ns{}{}      Substitution          yes*\ntr{}{}    Transliteration         no (but see below)\ny{}{}    Transliteration         no (but see below)\n<<EOF                 here-doc            yes*\n\n* unless the delimiter is ''.\n\nNon-bracketing delimiters use the same character fore and aft, but the four sorts of ASCII\nbrackets (round, angle, square, curly) all nest, which means that\n\nq{foo{bar}baz}\n\nis the same as\n\n'foo{bar}baz'\n\nNote, however, that this does not always work for quoting Perl code:\n\n$s = q{ if($x eq \"}\") ... }; # WRONG\n\nis a syntax error. The \"Text::Balanced\" module (standard as of v5.8, and from CPAN before then)\nis able to do this properly.\n\nThere can (and in some cases, must) be whitespace between the operator and the quoting\ncharacters, except when \"#\" is being used as the quoting character. \"q#foo#\" is parsed as the\nstring \"foo\", while \"q #foo#\" is the operator \"q\" followed by a comment. Its argument will be\ntaken from the next line. This allows you to write:\n\ns {foo}  # Replace foo\n{bar}  # with bar.\n\nThe cases where whitespace must be used are when the quoting character is a word character\n(meaning it matches \"/\\w/\"):\n\nq XfooX # Works: means the string 'foo'\nqXfooX  # WRONG!\n\nThe following escape sequences are available in constructs that interpolate, and in\ntransliterations whose delimiters aren't single quotes (\"'\"). In all the ones with braces, any\nnumber of blanks and/or tabs adjoining and within the braces are allowed (and ignored).\n\nSequence     Note  Description\n\\t                  tab               (HT, TAB)\n\\n                  newline           (NL)\n\\r                  return            (CR)\n\\f                  form feed         (FF)\n\\b                  backspace         (BS)\n\\a                  alarm (bell)      (BEL)\n\\e                  escape            (ESC)\n\\x{263A}     [1,8]  hex char          (example shown: SMILEY)\n\\x{ 263A }          Same, but shows optional blanks inside and\nadjoining the braces\n\\x1b         [2,8]  restricted range hex char (example: ESC)\n\\N{name}     [3]    named Unicode character or character sequence\n\\N{U+263D}   [4,8]  Unicode character (example: FIRST QUARTER MOON)\n\\c[          [5]    control char      (example: chr(27))\n\\o{23072}    [6,8]  octal char        (example: SMILEY)\n\\033         [7,8]  restricted range octal char  (example: ESC)\n\nNote that any escape sequence using braces inside interpolated constructs may have optional\nblanks (tab or space characters) adjoining with and inside of the braces, as illustrated above\nby the second \"\\x{ }\" example.\n\n[1] The result is the character specified by the hexadecimal number between the braces. See\n\"[8]\" below for details on which character.\n\nBlanks (tab or space characters) may separate the number from either or both of the braces.\n\nOtherwise, only hexadecimal digits are valid between the braces. If an invalid character is\nencountered, a warning will be issued and the invalid character and all subsequent\ncharacters (valid or invalid) within the braces will be discarded.\n\nIf there are no valid digits between the braces, the generated character is the NULL\ncharacter (\"\\x{00}\"). However, an explicit empty brace (\"\\x{}\") will not cause a warning\n(currently).\n\n[2] The result is the character specified by the hexadecimal number in the range 0x00 to 0xFF.\nSee \"[8]\" below for details on which character.\n\nOnly hexadecimal digits are valid following \"\\x\". When \"\\x\" is followed by fewer than two\nvalid digits, any valid digits will be zero-padded. This means that \"\\x7\" will be\ninterpreted as \"\\x07\", and a lone \"\\x\" will be interpreted as \"\\x00\". Except at the end of a\nstring, having fewer than two valid digits will result in a warning. Note that although the\nwarning says the illegal character is ignored, it is only ignored as part of the escape and\nwill still be used as the subsequent character in the string. For example:\n\nOriginal    Result    Warns?\n\"\\x7\"       \"\\x07\"    no\n\"\\x\"        \"\\x00\"    no\n\"\\x7q\"      \"\\x07q\"   yes\n\"\\xq\"       \"\\x00q\"   yes\n\n[3] The result is the Unicode character or character sequence given by *name*. See charnames.\n\n[4] \"\\N{U+*hexadecimal number*}\" means the Unicode character whose Unicode code point is\n*hexadecimal number*.\n\n[5] The character following \"\\c\" is mapped to some other character as shown in the table:\n\nSequence   Value\n\\c@      chr(0)\n\\cA      chr(1)\n\\ca      chr(1)\n\\cB      chr(2)\n\\cb      chr(2)\n...\n\\cZ      chr(26)\n\\cz      chr(26)\n\\c[      chr(27)\n# See below for chr(28)\n\\c]      chr(29)\n\\c^      chr(30)\n\\c      chr(31)\n\\c?      chr(127) # (on ASCII platforms; see below for link to\n#  EBCDIC discussion)\n\nIn other words, it's the character whose code point has had 64 xor'd with its uppercase.\n\"\\c?\" is DELETE on ASCII platforms because \"ord(\"?\") ^ 64\" is 127, and \"\\c@\" is NULL because\nthe ord of \"@\" is 64, so xor'ing 64 itself produces 0.\n\nAlso, \"\\c\\*X*\" yields \" chr(28) . \"*X*\"\" for any *X*, but cannot come at the end of a\nstring, because the backslash would be parsed as escaping the end quote.\n\nOn ASCII platforms, the resulting characters from the list above are the complete set of\nASCII controls. This isn't the case on EBCDIC platforms; see \"OPERATOR DIFFERENCES\" in\nperlebcdic for a full discussion of the differences between these for ASCII versus EBCDIC\nplatforms.\n\nUse of any other character following the \"c\" besides those listed above is discouraged, and\nas of Perl v5.20, the only characters actually allowed are the printable ASCII ones, minus\nthe left brace \"{\". What happens for any of the allowed other characters is that the value\nis derived by xor'ing with the seventh bit, which is 64, and a warning raised if enabled.\nUsing the non-allowed characters generates a fatal error.\n\nTo get platform independent controls, you can use \"\\N{...}\".\n\n[6] The result is the character specified by the octal number between the braces. See \"[8]\"\nbelow for details on which character.\n\nBlanks (tab or space characters) may separate the number from either or both of the braces.\n\nOtherwise, if a character that isn't an octal digit is encountered, a warning is raised, and\nthe value is based on the octal digits before it, discarding it and all following characters\nup to the closing brace. It is a fatal error if there are no octal digits at all.\n\n[7] The result is the character specified by the three-digit octal number in the range 000 to\n777 (but best to not use above 077, see next paragraph). See \"[8]\" below for details on\nwhich character.\n\nSome contexts allow 2 or even 1 digit, but any usage without exactly three digits, the first\nbeing a zero, may give unintended results. (For example, in a regular expression it may be\nconfused with a backreference; see \"Octal escapes\" in perlrebackslash.) Starting in Perl\n5.14, you may use \"\\o{}\" instead, which avoids all these problems. Otherwise, it is best to\nuse this construct only for ordinals \"\\077\" and below, remembering to pad to the left with\nzeros to make three digits. For larger ordinals, either use \"\\o{}\", or convert to something\nelse, such as to hex and use \"\\N{U+}\" (which is portable between platforms with different\ncharacter sets) or \"\\x{}\" instead.\n\n[8] Several constructs above specify a character by a number. That number gives the character's\nposition in the character set encoding (indexed from 0). This is called synonymously its\nordinal, code position, or code point. Perl works on platforms that have a native encoding\ncurrently of either ASCII/Latin1 or EBCDIC, each of which allow specification of 256\ncharacters. In general, if the number is 255 (0xFF, 0377) or below, Perl interprets this in\nthe platform's native encoding. If the number is 256 (0x100, 0400) or above, Perl interprets\nit as a Unicode code point and the result is the corresponding Unicode character. For\nexample \"\\x{50}\" and \"\\o{120}\" both are the number 80 in decimal, which is less than 256, so\nthe number is interpreted in the native character set encoding. In ASCII the character in\nthe 80th position (indexed from 0) is the letter \"P\", and in EBCDIC it is the ampersand\nsymbol \"&\". \"\\x{100}\" and \"\\o{400}\" are both 256 in decimal, so the number is interpreted as\na Unicode code point no matter what the native encoding is. The name of the character in the\n256th position (indexed by 0) in Unicode is \"LATIN CAPITAL LETTER A WITH MACRON\".\n\nAn exception to the above rule is that \"\\N{U+*hex number*}\" is always interpreted as a\nUnicode code point, so that \"\\N{U+0050}\" is \"P\" even on EBCDIC platforms.\n\nNOTE: Unlike C and other languages, Perl has no \"\\v\" escape sequence for the vertical tab (VT,\nwhich is 11 in both ASCII and EBCDIC), but you may use \"\\N{VT}\", \"\\ck\", \"\\N{U+0b}\", or \"\\x0b\".\n(\"\\v\" does have meaning in regular expression patterns in Perl, see perlre.)\n\nThe following escape sequences are available in constructs that interpolate, but not in\ntransliterations.\n\n\\l          lowercase next character only\n\\u          titlecase (not uppercase!) next character only\n\\L          lowercase all characters till \\E or end of string\n\\U          uppercase all characters till \\E or end of string\n\\F          foldcase all characters till \\E or end of string\n\\Q          quote (disable) pattern metacharacters till \\E or\nend of string\n\\E          end either case modification or quoted section\n(whichever was last seen)\n\nSee \"quotemeta\" in perlfunc for the exact definition of characters that are quoted by \"\\Q\".\n\n\"\\L\", \"\\U\", \"\\F\", and \"\\Q\" can stack, in which case you need one \"\\E\" for each. For example:\n\nsay\"This \\Qquoting \\ubusiness \\Uhere isn't quite\\E done yet,\\E is it?\";\nThis quoting\\ Business\\ HERE\\ ISN\\'T\\ QUITE\\ done\\ yet\\, is it?\n\nIf a \"use locale\" form that includes \"LCCTYPE\" is in effect (see perllocale), the case map used\nby \"\\l\", \"\\L\", \"\\u\", and \"\\U\" is taken from the current locale. If Unicode (for example, \"\\N{}\"\nor code points of 0x100 or beyond) is being used, the case map used by \"\\l\", \"\\L\", \"\\u\", and\n\"\\U\" is as defined by Unicode. That means that case-mapping a single character can sometimes\nproduce a sequence of several characters. Under \"use locale\", \"\\F\" produces the same results as\n\"\\L\" for all locales but a UTF-8 one, where it instead uses the Unicode definition.\n\nAll systems use the virtual \"\\n\" to represent a line terminator, called a \"newline\". There is no\nsuch thing as an unvarying, physical newline character. It is only an illusion that the\noperating system, device drivers, C libraries, and Perl all conspire to preserve. Not all\nsystems read \"\\r\" as ASCII CR and \"\\n\" as ASCII LF. For example, on the ancient Macs (pre-MacOS\nX) of yesteryear, these used to be reversed, and on systems without a line terminator, printing\n\"\\n\" might emit no actual data. In general, use \"\\n\" when you mean a \"newline\" for your system,\nbut use the literal ASCII when you need an exact character. For example, most networking\nprotocols expect and prefer a CR+LF (\"\\015\\012\" or \"\\cM\\cJ\") for line terminators, and although\nthey often accept just \"\\012\", they seldom tolerate just \"\\015\". If you get in the habit of\nusing \"\\n\" for networking, you may be burned some day.\n\nFor constructs that do interpolate, variables beginning with \"\"$\"\" or \"\"@\"\" are interpolated.\nSubscripted variables such as $a[3] or \"$href->{key}[0]\" are also interpolated, as are array and\nhash slices. But method calls such as \"$obj->meth\" are not.\n\nInterpolating an array or slice interpolates the elements in order, separated by the value of\n$\", so is equivalent to interpolating \"join $\", @array\". \"Punctuation\" arrays such as \"@*\" are\nusually interpolated only if the name is enclosed in braces \"@{*}\", but the arrays @, \"@+\", and\n\"@-\" are interpolated even without braces.\n\nFor double-quoted strings, the quoting from \"\\Q\" is applied after interpolation and escapes are\nprocessed.\n\n\"abc\\Qfoo\\tbar$s\\Exyz\"\n\nis equivalent to\n\n\"abc\" . quotemeta(\"foo\\tbar$s\") . \"xyz\"\n\nFor the pattern of regex operators (\"qr//\", \"m//\" and \"s///\"), the quoting from \"\\Q\" is applied\nafter interpolation is processed, but before escapes are processed. This allows the pattern to\nmatch literally (except for \"$\" and \"@\"). For example, the following matches:\n\n'\\s\\t' =~ /\\Q\\s\\t/\n\nBecause \"$\" or \"@\" trigger interpolation, you'll need to use something like \"/\\Quser\\E\\@\\Qhost/\"\nto match them literally.\n\nPatterns are subject to an additional level of interpretation as a regular expression. This is\ndone as a second pass, after variables are interpolated, so that regular expressions may be\nincorporated into the pattern from the variables. If this is not what you want, use \"\\Q\" to\ninterpolate a variable literally.\n\nApart from the behavior described above, Perl does not expand multiple levels of interpolation.\nIn particular, contrary to the expectations of shell programmers, back-quotes do *NOT*\ninterpolate within double quotes, nor do single quotes impede evaluation of variables when used\nwithin double quotes.\n"
                },
                {
                    "name": "Regexp Quote-Like Operators",
                    "content": "Here are the quote-like operators that apply to pattern matching and related activities.\n\n\"qr/*STRING*/msixpodualn\"\nThis operator quotes (and possibly compiles) its *STRING* as a regular expression.\n*STRING* is interpolated the same way as *PATTERN* in \"m/*PATTERN*/\". If \"'\" is used as\nthe delimiter, no variable interpolation is done. Returns a Perl value which may be used\ninstead of the corresponding \"/*STRING*/msixpodualn\" expression. The returned value is a\nnormalized version of the original pattern. It magically differs from a string\ncontaining the same characters: \"ref(qr/x/)\" returns \"Regexp\"; however, dereferencing it\nis not well defined (you currently get the normalized version of the original pattern,\nbut this may change).\n\nFor example,\n\n$rex = qr/my.STRING/is;\nprint $rex;                 # prints (?si-xm:my.STRING)\ns/$rex/foo/;\n\nis equivalent to\n\ns/my.STRING/foo/is;\n\nThe result may be used as a subpattern in a match:\n\n$re = qr/$pattern/;\n$string =~ /foo${re}bar/;   # can be interpolated in other\n# patterns\n$string =~ $re;             # or used standalone\n$string =~ /$re/;           # or this way\n\nSince Perl may compile the pattern at the moment of execution of the \"qr()\" operator,\nusing \"qr()\" may have speed advantages in some situations, notably if the result of\n\"qr()\" is used standalone:\n\nsub match {\nmy $patterns = shift;\nmy @compiled = map qr/$/i, @$patterns;\ngrep {\nmy $success = 0;\nforeach my $pat (@compiled) {\n$success = 1, last if /$pat/;\n}\n$success;\n} @;\n}\n\nPrecompilation of the pattern into an internal representation at the moment of \"qr()\"\navoids the need to recompile the pattern every time a match \"/$pat/\" is attempted. (Perl\nhas many other internal optimizations, but none would be triggered in the above example\nif we did not use \"qr()\" operator.)\n\nOptions (specified by the following modifiers) are:\n\nm   Treat string as multiple lines.\ns   Treat string as single line. (Make . match a newline)\ni   Do case-insensitive pattern matching.\nx   Use extended regular expressions; specifying two\nx's means \\t and the SPACE character are ignored within\nsquare-bracketed character classes\np   When matching preserve a copy of the matched string so\nthat ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH} will be\ndefined (ignored starting in v5.20) as these are always\ndefined starting in that release\no   Compile pattern only once.\na   ASCII-restrict: Use ASCII for \\d, \\s, \\w and [[:posix:]]\ncharacter classes; specifying two a's adds the further\nrestriction that no ASCII character will match a\nnon-ASCII one under /i.\nl   Use the current run-time locale's rules.\nu   Use Unicode rules.\nd   Use Unicode or native charset, as in 5.12 and earlier.\nn   Non-capture mode. Don't let () fill in $1, $2, etc...\n\nIf a precompiled pattern is embedded in a larger pattern then the effect of \"msixpluadn\"\nwill be propagated appropriately. The effect that the \"/o\" modifier has is not\npropagated, being restricted to those patterns explicitly using it.\n\nThe \"/a\", \"/d\", \"/l\", and \"/u\" modifiers (added in Perl 5.14) control the character set\nrules, but \"/a\" is the only one you are likely to want to specify explicitly; the other\nthree are selected automatically by various pragmas.\n\nSee perlre for additional information on valid syntax for *STRING*, and for a detailed\nlook at the semantics of regular expressions. In particular, all modifiers except the\nlargely obsolete \"/o\" are further explained in \"Modifiers\" in perlre. \"/o\" is described\nin the next section.\n\n\"m/*PATTERN*/msixpodualngc\"\n\"/*PATTERN*/msixpodualngc\"\nSearches a string for a pattern match, and in scalar context returns true if it\nsucceeds, false if it fails. If no string is specified via the \"=~\" or \"!~\" operator,\nthe $ string is searched. (The string specified with \"=~\" need not be an lvalue--it may\nbe the result of an expression evaluation, but remember the \"=~\" binds rather tightly.)\nSee also perlre.\n\nOptions are as described in \"qr//\" above; in addition, the following match process\nmodifiers are available:\n\ng  Match globally, i.e., find all occurrences.\nc  Do not reset search position on a failed match when /g is\nin effect.\n\nIf \"/\" is the delimiter then the initial \"m\" is optional. With the \"m\" you can use any\npair of non-whitespace (ASCII) characters as delimiters. This is particularly useful for\nmatching path names that contain \"/\", to avoid LTS (leaning toothpick syndrome). If \"?\"\nis the delimiter, then a match-only-once rule applies, described in \"m?*PATTERN*?\"\nbelow. If \"'\" (single quote) is the delimiter, no variable interpolation is performed on\nthe *PATTERN*. When using a delimiter character valid in an identifier, whitespace is\nrequired after the \"m\".\n\n*PATTERN* may contain variables, which will be interpolated every time the pattern\nsearch is evaluated, except for when the delimiter is a single quote. (Note that $(, $),\nand $| are not interpolated because they look like end-of-string tests.) Perl will not\nrecompile the pattern unless an interpolated variable that it contains changes. You can\nforce Perl to skip the test and never recompile by adding a \"/o\" (which stands for\n\"once\") after the trailing delimiter. Once upon a time, Perl would recompile regular\nexpressions unnecessarily, and this modifier was useful to tell it not to do so, in the\ninterests of speed. But now, the only reasons to use \"/o\" are one of:\n\n1   The variables are thousands of characters long and you know that they don't change,\nand you need to wring out the last little bit of speed by having Perl skip testing\nfor that. (There is a maintenance penalty for doing this, as mentioning \"/o\"\nconstitutes a promise that you won't change the variables in the pattern. If you do\nchange them, Perl won't even notice.)\n\n2   you want the pattern to use the initial values of the variables regardless of\nwhether they change or not. (But there are saner ways of accomplishing this than\nusing \"/o\".)\n\n3   If the pattern contains embedded code, such as\n\nuse re 'eval';\n$code = 'foo(?{ $x })';\n/$code/\n\nthen perl will recompile each time, even though the pattern string hasn't changed,\nto ensure that the current value of $x is seen each time. Use \"/o\" if you want to\navoid this.\n\nThe bottom line is that using \"/o\" is almost never a good idea.\n\nThe empty pattern \"//\"\nIf the *PATTERN* evaluates to the empty string, the last *successfully* matched regular\nexpression is used instead. In this case, only the \"g\" and \"c\" flags on the empty\npattern are honored; the other flags are taken from the original pattern. If no match\nhas previously succeeded, this will (silently) act instead as a genuine empty pattern\n(which will always match).\n\nNote that it's possible to confuse Perl into thinking \"//\" (the empty regex) is really\n\"//\" (the defined-or operator). Perl is usually pretty good about this, but some\npathological cases might trigger this, such as \"$x///\" (is that \"($x) / (//)\" or\n\"$x // /\"?) and \"print $fh //\" (\"print $fh(//\" or \"print($fh //\"?). In all of these\nexamples, Perl will assume you meant defined-or. If you meant the empty regex, just use\nparentheses or spaces to disambiguate, or even prefix the empty regex with an \"m\" (so\n\"//\" becomes \"m//\").\n\nMatching in list context\nIf the \"/g\" option is not used, \"m//\" in list context returns a list consisting of the\nsubexpressions matched by the parentheses in the pattern, that is, ($1, $2, $3...) (Note\nthat here $1 etc. are also set). When there are no parentheses in the pattern, the\nreturn value is the list \"(1)\" for success. With or without parentheses, an empty list\nis returned upon failure.\n\nExamples:\n\nopen(TTY, \"+</dev/tty\")\n|| die \"can't access /dev/tty: $!\";\n\n<TTY> =~ /^y/i && foo();       # do foo if desired\n\nif (/Version: *([0-9.]*)/) { $version = $1; }\n\nnext if m#^/usr/spool/uucp#;\n\n# poor man's grep\n$arg = shift;\nwhile (<>) {\nprint if /$arg/o; # compile only once (no longer needed!)\n}\n\nif (($F1, $F2, $Etc) = ($foo =~ /^(\\S+)\\s+(\\S+)\\s*(.*)/))\n\nThis last example splits $foo into the first two words and the remainder of the line,\nand assigns those three fields to $F1, $F2, and $Etc. The conditional is true if any\nvariables were assigned; that is, if the pattern matched.\n\nThe \"/g\" modifier specifies global pattern matching--that is, matching as many times as\npossible within the string. How it behaves depends on the context. In list context, it\nreturns a list of the substrings matched by any capturing parentheses in the regular\nexpression. If there are no parentheses, it returns a list of all the matched strings,\nas if there were parentheses around the whole pattern.\n\nIn scalar context, each execution of \"m//g\" finds the next match, returning true if it\nmatches, and false if there is no further match. The position after the last match can\nbe read or set using the \"pos()\" function; see \"pos\" in perlfunc. A failed match\nnormally resets the search position to the beginning of the string, but you can avoid\nthat by adding the \"/c\" modifier (for example, \"m//gc\"). Modifying the target string\nalso resets the search position.\n\n\"\\G *assertion*\"\nYou can intermix \"m//g\" matches with \"m/\\G.../g\", where \"\\G\" is a zero-width assertion\nthat matches the exact position where the previous \"m//g\", if any, left off. Without the\n\"/g\" modifier, the \"\\G\" assertion still anchors at \"pos()\" as it was at the start of the\noperation (see \"pos\" in perlfunc), but the match is of course only attempted once. Using\n\"\\G\" without \"/g\" on a target string that has not previously had a \"/g\" match applied to\nit is the same as using the \"\\A\" assertion to match the beginning of the string. Note\nalso that, currently, \"\\G\" is only properly supported when anchored at the very\nbeginning of the pattern.\n\nExamples:\n\n# list context\n($one,$five,$fifteen) = (`uptime` =~ /(\\d+\\.\\d+)/g);\n\n# scalar context\nlocal $/ = \"\";\nwhile ($paragraph = <>) {\nwhile ($paragraph =~ /\\p{Ll}['\")]*[.!?]+['\")]*\\s/g) {\n$sentences++;\n}\n}\nsay $sentences;\n\nHere's another way to check for sentences in a paragraph:\n\nmy $sentencerx = qr{\n(?: (?<= ^ ) | (?<= \\s ) )  # after start-of-string or\n# whitespace\n\\p{Lu}                      # capital letter\n.*?                         # a bunch of anything\n(?<= \\S )                   # that ends in non-\n# whitespace\n(?<! \\b [DMS]r  )           # but isn't a common abbr.\n(?<! \\b Mrs )\n(?<! \\b Sra )\n(?<! \\b St  )\n[.?!]                       # followed by a sentence\n# ender\n(?= $ | \\s )                # in front of end-of-string\n# or whitespace\n}sx;\nlocal $/ = \"\";\nwhile (my $paragraph = <>) {\nsay \"NEW PARAGRAPH\";\nmy $count = 0;\nwhile ($paragraph =~ /($sentencerx)/g) {\nprintf \"\\tgot sentence %d: <%s>\\n\", ++$count, $1;\n}\n}\n\nHere's how to use \"m//gc\" with \"\\G\":\n\n$ = \"ppooqppqq\";\nwhile ($i++ < 2) {\nprint \"1: '\";\nprint $1 while /(o)/gc; print \"', pos=\", pos, \"\\n\";\nprint \"2: '\";\nprint $1 if /\\G(q)/gc;  print \"', pos=\", pos, \"\\n\";\nprint \"3: '\";\nprint $1 while /(p)/gc; print \"', pos=\", pos, \"\\n\";\n}\nprint \"Final: '$1', pos=\",pos,\"\\n\" if /\\G(.)/;\n\nThe last example should print:\n\n1: 'oo', pos=4\n2: 'q', pos=5\n3: 'pp', pos=7\n1: '', pos=7\n2: 'q', pos=8\n3: '', pos=8\nFinal: 'q', pos=8\n\nNotice that the final match matched \"q\" instead of \"p\", which a match without the \"\\G\"\nanchor would have done. Also note that the final match did not update \"pos\". \"pos\" is\nonly updated on a \"/g\" match. If the final match did indeed match \"p\", it's a good bet\nthat you're running an ancient (pre-5.6.0) version of Perl.\n\nA useful idiom for \"lex\"-like scanners is \"/\\G.../gc\". You can combine several regexps\nlike this to process a string part-by-part, doing different actions depending on which\nregexp matched. Each regexp tries to match where the previous one leaves off.\n\n$ = <<'EOL';\n$url = URI::URL->new( \"http://example.com/\" );\ndie if $url eq \"xXx\";\nEOL\n\nLOOP: {\nprint(\" digits\"),       redo LOOP if /\\G\\d+\\b[,.;]?\\s*/gc;\nprint(\" lowercase\"),    redo LOOP\nif /\\G\\p{Ll}+\\b[,.;]?\\s*/gc;\nprint(\" UPPERCASE\"),    redo LOOP\nif /\\G\\p{Lu}+\\b[,.;]?\\s*/gc;\nprint(\" Capitalized\"),  redo LOOP\nif /\\G\\p{Lu}\\p{Ll}+\\b[,.;]?\\s*/gc;\nprint(\" MiXeD\"),        redo LOOP if /\\G\\pL+\\b[,.;]?\\s*/gc;\nprint(\" alphanumeric\"), redo LOOP\nif /\\G[\\p{Alpha}\\pN]+\\b[,.;]?\\s*/gc;\nprint(\" line-noise\"),   redo LOOP if /\\G\\W+/gc;\nprint \". That's all!\\n\";\n}\n\nHere is the output (split into several lines):\n\nline-noise lowercase line-noise UPPERCASE line-noise UPPERCASE\nline-noise lowercase line-noise lowercase line-noise lowercase\nlowercase line-noise lowercase lowercase line-noise lowercase\nlowercase line-noise MiXeD line-noise. That's all!\n\n\"m?*PATTERN*?msixpodualngc\"\nThis is just like the \"m/*PATTERN*/\" search, except that it matches only once between\ncalls to the \"reset()\" operator. This is a useful optimization when you want to see only\nthe first occurrence of something in each file of a set of files, for instance. Only\n\"m??\" patterns local to the current package are reset.\n\nwhile (<>) {\nif (m?^$?) {\n# blank line between header and body\n}\n} continue {\nreset if eof;       # clear m?? status for next file\n}\n\nAnother example switched the first \"latin1\" encoding it finds to \"utf8\" in a pod file:\n\ns//utf8/ if m? ^ =encoding \\h+ \\K latin1 ?x;\n\nThe match-once behavior is controlled by the match delimiter being \"?\"; with any other\ndelimiter this is the normal \"m//\" operator.\n\nIn the past, the leading \"m\" in \"m?*PATTERN*?\" was optional, but omitting it would\nproduce a deprecation warning. As of v5.22.0, omitting it produces a syntax error. If\nyou encounter this construct in older code, you can just add \"m\".\n\n\"s/*PATTERN*/*REPLACEMENT*/msixpodualngcer\"\nSearches a string for a pattern, and if found, replaces that pattern with the\nreplacement text and returns the number of substitutions made. Otherwise it returns\nfalse (a value that is both an empty string (\"\") and numeric zero (0) as described in\n\"Relational Operators\").\n\nIf the \"/r\" (non-destructive) option is used then it runs the substitution on a copy of\nthe string and instead of returning the number of substitutions, it returns the copy\nwhether or not a substitution occurred. The original string is never changed when \"/r\"\nis used. The copy will always be a plain string, even if the input is an object or a\ntied variable.\n\nIf no string is specified via the \"=~\" or \"!~\" operator, the $ variable is searched and\nmodified. Unless the \"/r\" option is used, the string specified must be a scalar\nvariable, an array element, a hash element, or an assignment to one of those; that is,\nsome sort of scalar lvalue.\n\nIf the delimiter chosen is a single quote, no variable interpolation is done on either\nthe *PATTERN* or the *REPLACEMENT*. Otherwise, if the *PATTERN* contains a \"$\" that\nlooks like a variable rather than an end-of-string test, the variable will be\ninterpolated into the pattern at run-time. If you want the pattern compiled only once\nthe first time the variable is interpolated, use the \"/o\" option. If the pattern\nevaluates to the empty string, the last successfully executed regular expression is used\ninstead. See perlre for further explanation on these.\n\nOptions are as with \"m//\" with the addition of the following replacement specific\noptions:\n\ne   Evaluate the right side as an expression.\nee  Evaluate the right side as a string then eval the\nresult.\nr   Return substitution and leave the original string\nuntouched.\n\nAny non-whitespace delimiter may replace the slashes. Add space after the \"s\" when using\na character allowed in identifiers. If single quotes are used, no interpretation is done\non the replacement string (the \"/e\" modifier overrides this, however). Note that Perl\ntreats backticks as normal delimiters; the replacement text is not evaluated as a\ncommand. If the *PATTERN* is delimited by bracketing quotes, the *REPLACEMENT* has its\nown pair of quotes, which may or may not be bracketing quotes, for example,\n\"s(foo)(bar)\" or \"s<foo>/bar/\". A \"/e\" will cause the replacement portion to be treated\nas a full-fledged Perl expression and evaluated right then and there. It is, however,\nsyntax checked at compile-time. A second \"e\" modifier will cause the replacement portion\nto be \"eval\"ed before being run as a Perl expression.\n\nExamples:\n\ns/\\bgreen\\b/mauve/g;              # don't change wintergreen\n\n$path =~ s|/usr/bin|/usr/local/bin|;\n\ns/Login: $foo/Login: $bar/; # run-time pattern\n\n($foo = $bar) =~ s/this/that/;      # copy first, then\n# change\n($foo = \"$bar\") =~ s/this/that/;    # convert to string,\n# copy, then change\n$foo = $bar =~ s/this/that/r;       # Same as above using /r\n$foo = $bar =~ s/this/that/r\n=~ s/that/the other/r;  # Chained substitutes\n# using /r\n@foo = map { s/this/that/r } @bar   # /r is very useful in\n# maps\n\n$count = ($paragraph =~ s/Mister\\b/Mr./g);  # get change-cnt\n\n$ = 'abc123xyz';\ns/\\d+/$&*2/e;               # yields 'abc246xyz'\ns/\\d+/sprintf(\"%5d\",$&)/e;  # yields 'abc  246xyz'\ns/\\w/$& x 2/eg;             # yields 'aabbcc  224466xxyyzz'\n\ns/%(.)/$percent{$1}/g;      # change percent escapes; no /e\ns/%(.)/$percent{$1} || $&/ge;       # expr now, so /e\ns/^=(\\w+)/pod($1)/ge;       # use function call\n\n$ = 'abc123xyz';\n$x = s/abc/def/r;           # $x is 'def123xyz' and\n# $ remains 'abc123xyz'.\n\n# expand variables in $, but dynamics only, using\n# symbolic dereferencing\ns/\\$(\\w+)/${$1}/g;\n\n# Add one to the value of any numbers in the string\ns/(\\d+)/1 + $1/eg;\n\n# Titlecase words in the last 30 characters only\nsubstr($str, -30) =~ s/\\b(\\p{Alpha}+)\\b/\\u\\L$1/g;\n\n# This will expand any embedded scalar variable\n# (including lexicals) in $ : First $1 is interpolated\n# to the variable name, and then evaluated\ns/(\\$\\w+)/$1/eeg;\n\n# Delete (most) C comments.\n$program =~ s {\n/\\*     # Match the opening delimiter.\n.*?     # Match a minimal number of characters.\n\\*/     # Match the closing delimiter.\n} []gsx;\n\ns/^\\s*(.*?)\\s*$/$1/;        # trim whitespace in $,\n# expensively\n\nfor ($variable) {           # trim whitespace in $variable,\n# cheap\ns/^\\s+//;\ns/\\s+$//;\n}\n\ns/([^ ]*) *([^ ]*)/$2 $1/;  # reverse 1st two fields\n\n$foo !~ s/A/a/g;    # Lowercase all A's in $foo; return\n# 0 if any were found and changed;\n# otherwise return 1\n\nNote the use of \"$\" instead of \"\\\" in the last example. Unlike sed, we use the\n\\<*digit*> form only in the left hand side. Anywhere else it's $<*digit*>.\n\nOccasionally, you can't use just a \"/g\" to get all the changes to occur that you might\nwant. Here are two common cases:\n\n# put commas in the right places in an integer\n1 while s/(\\d)(\\d\\d\\d)(?!\\d)/$1,$2/g;\n\n# expand tabs to 8-column spacing\n1 while s/\\t+/' ' x (length($&)*8 - length($`)%8)/e;\n\nWhile \"s///\" accepts the \"/c\" flag, it has no effect beyond producing a warning if\nwarnings are enabled.\n"
                },
                {
                    "name": "Quote-Like Operators",
                    "content": "\"q/*STRING*/\"\n'*STRING*'\nA single-quoted, literal string. A backslash represents a backslash unless followed by the\ndelimiter or another backslash, in which case the delimiter or backslash is interpolated.\n\n$foo = q!I said, \"You said, 'She said it.'\"!;\n$bar = q('This is it.');\n$baz = '\\n';                # a two-character string\n\n\"qq/*STRING*/\"\n\"*STRING*\"\nA double-quoted, interpolated string.\n\n$ .= qq\n(* The previous line contains the naughty word \"$1\".\\n)\nif /\\b(tcl|java|python)\\b/i;      # :-)\n$baz = \"\\n\";                # a one-character string\n\n\"qx/*STRING*/\"\n`*STRING*`\nA string which is (possibly) interpolated and then executed as a system command, via /bin/sh\nor its equivalent if required. Shell wildcards, pipes, and redirections will be honored.\nSimilarly to \"system\", if the string contains no shell metacharacters then it will executed\ndirectly. The collected standard output of the command is returned; standard error is\nunaffected. In scalar context, it comes back as a single (potentially multi-line) string, or\n\"undef\" if the shell (or command) could not be started. In list context, returns a list of\nlines (however you've defined lines with $/ or $INPUTRECORDSEPARATOR), or an empty list if\nthe shell (or command) could not be started.\n\nBecause backticks do not affect standard error, use shell file descriptor syntax (assuming\nthe shell supports this) if you care to address this. To capture a command's STDERR and\nSTDOUT together:\n\n$output = `cmd 2>&1`;\n\nTo capture a command's STDOUT but discard its STDERR:\n\n$output = `cmd 2>/dev/null`;\n\nTo capture a command's STDERR but discard its STDOUT (ordering is important here):\n\n$output = `cmd 2>&1 1>/dev/null`;\n\nTo exchange a command's STDOUT and STDERR in order to capture the STDERR but leave its\nSTDOUT to come out the old STDERR:\n\n$output = `cmd 3>&1 1>&2 2>&3 3>&-`;\n\nTo read both a command's STDOUT and its STDERR separately, it's easiest to redirect them\nseparately to files, and then read from those files when the program is done:\n\nsystem(\"program args 1>program.stdout 2>program.stderr\");\n\nThe STDIN filehandle used by the command is inherited from Perl's STDIN. For example:\n\nopen(SPLAT, \"stuff\")   || die \"can't open stuff: $!\";\nopen(STDIN, \"<&SPLAT\") || die \"can't dupe SPLAT: $!\";\nprint STDOUT `sort`;\n\nwill print the sorted contents of the file named \"stuff\".\n\nUsing single-quote as a delimiter protects the command from Perl's double-quote\ninterpolation, passing it on to the shell instead:\n\n$perlinfo  = qx(ps $$);            # that's Perl's $$\n$shellinfo = qx'ps $$';            # that's the new shell's $$\n\nHow that string gets evaluated is entirely subject to the command interpreter on your\nsystem. On most platforms, you will have to protect shell metacharacters if you want them\ntreated literally. This is in practice difficult to do, as it's unclear how to escape which\ncharacters. See perlsec for a clean and safe example of a manual \"fork()\" and \"exec()\" to\nemulate backticks safely.\n\nOn some platforms (notably DOS-like ones), the shell may not be capable of dealing with\nmultiline commands, so putting newlines in the string may not get you what you want. You may\nbe able to evaluate multiple commands in a single line by separating them with the command\nseparator character, if your shell supports that (for example, \";\" on many Unix shells and\n\"&\" on the Windows NT \"cmd\" shell).\n\nPerl will attempt to flush all files opened for output before starting the child process,\nbut this may not be supported on some platforms (see perlport). To be safe, you may need to\nset $| ($AUTOFLUSH in \"English\") or call the \"autoflush()\" method of \"IO::Handle\" on any\nopen handles.\n\nBeware that some command shells may place restrictions on the length of the command line.\nYou must ensure your strings don't exceed this limit after any necessary interpolations. See\nthe platform-specific release notes for more details about your particular environment.\n\nUsing this operator can lead to programs that are difficult to port, because the shell\ncommands called vary between systems, and may in fact not be present at all. As one example,\nthe \"type\" command under the POSIX shell is very different from the \"type\" command under\nDOS. That doesn't mean you should go out of your way to avoid backticks when they're the\nright way to get something done. Perl was made to be a glue language, and one of the things\nit glues together is commands. Just understand what you're getting yourself into.\n\nLike \"system\", backticks put the child process exit code in $?. If you'd like to manually\ninspect failure, you can check all possible failure modes by inspecting $? like this:\n\nif ($? == -1) {\nprint \"failed to execute: $!\\n\";\n}\nelsif ($? & 127) {\nprintf \"child died with signal %d, %s coredump\\n\",\n($? & 127),  ($? & 128) ? 'with' : 'without';\n}\nelse {\nprintf \"child exited with value %d\\n\", $? >> 8;\n}\n\nUse the open pragma to control the I/O layers used when reading the output of the command,\nfor example:\n\nuse open IN => \":encoding(UTF-8)\";\nmy $x = `cmd-producing-utf-8`;\n\n\"qx//\" can also be called like a function with \"readpipe\" in perlfunc.\n\nSee \"I/O Operators\" for more discussion.\n\n\"qw/*STRING*/\"\nEvaluates to a list of the words extracted out of *STRING*, using embedded whitespace as the\nword delimiters. It can be understood as being roughly equivalent to:\n\nsplit(\" \", q/STRING/);\n\nthe differences being that it only splits on ASCII whitespace, generates a real list at\ncompile time, and in scalar context it returns the last element in the list. So this\nexpression:\n\nqw(foo bar baz)\n\nis semantically equivalent to the list:\n\n\"foo\", \"bar\", \"baz\"\n\nSome frequently seen examples:\n\nuse POSIX qw( setlocale localeconv )\n@EXPORT = qw( foo bar baz );\n\nA common mistake is to try to separate the words with commas or to put comments into a\nmulti-line \"qw\"-string. For this reason, the \"use warnings\" pragma and the -w switch (that\nis, the $^W variable) produces warnings if the *STRING* contains the \",\" or the \"#\"\ncharacter.\n\n\"tr/*SEARCHLIST*/*REPLACEMENTLIST*/cdsr\"\n\"y/*SEARCHLIST*/*REPLACEMENTLIST*/cdsr\"\nTransliterates all occurrences of the characters found (or not found if the \"/c\" modifier is\nspecified) in the search list with the positionally corresponding character in the\nreplacement list, possibly deleting some, depending on the modifiers specified. It returns\nthe number of characters replaced or deleted. If no string is specified via the \"=~\" or \"!~\"\noperator, the $ string is transliterated.\n\nFor sed devotees, \"y\" is provided as a synonym for \"tr\".\n\nIf the \"/r\" (non-destructive) option is present, a new copy of the string is made and its\ncharacters transliterated, and this copy is returned no matter whether it was modified or\nnot: the original string is always left unchanged. The new copy is always a plain string,\neven if the input string is an object or a tied variable.\n\nUnless the \"/r\" option is used, the string specified with \"=~\" must be a scalar variable, an\narray element, a hash element, or an assignment to one of those; in other words, an lvalue.\n\nThe characters delimitting *SEARCHLIST* and *REPLACEMENTLIST* can be any printable\ncharacter, not just forward slashes. If they are single quotes\n(\"tr'*SEARCHLIST*'*REPLACEMENTLIST*'\"), the only interpolation is removal of \"\\\" from pairs\nof \"\\\\\".\n\nOtherwise, a character range may be specified with a hyphen, so \"tr/A-J/0-9/\" does the same\nreplacement as \"tr/ACEGIBDFHJ/0246813579/\".\n\nIf the *SEARCHLIST* is delimited by bracketing quotes, the *REPLACEMENTLIST* must have its\nown pair of quotes, which may or may not be bracketing quotes; for example,\n\"tr[aeiouy][yuoiea]\" or \"tr(+\\-*/)/ABCD/\".\n\nCharacters may be literals, or (if the delimiters aren't single quotes) any of the escape\nsequences accepted in double-quoted strings. But there is never any variable interpolation,\nso \"$\" and \"@\" are always treated as literals. A hyphen at the beginning or end, or preceded\nby a backslash is also always considered a literal. Escape sequence details are in the table\nnear the beginning of this section.\n\nNote that \"tr\" does not do regular expression character classes such as \"\\d\" or \"\\pL\". The\n\"tr\" operator is not equivalent to the tr(1) utility. \"tr[a-z][A-Z]\" will uppercase the 26\nletters \"a\" through \"z\", but for case changing not confined to ASCII, use \"lc\", \"uc\",\n\"lcfirst\", \"ucfirst\" (all documented in perlfunc), or the substitution operator\n\"s/*PATTERN*/*REPLACEMENT*/\" (with \"\\U\", \"\\u\", \"\\L\", and \"\\l\" string-interpolation escapes\nin the *REPLACEMENT* portion).\n\nMost ranges are unportable between character sets, but certain ones signal Perl to do\nspecial handling to make them portable. There are two classes of portable ranges. The first\nare any subsets of the ranges \"A-Z\", \"a-z\", and \"0-9\", when expressed as literal characters.\n\ntr/h-k/H-K/\n\ncapitalizes the letters \"h\", \"i\", \"j\", and \"k\" and nothing else, no matter what the\nplatform's character set is. In contrast, all of\n\ntr/\\x68-\\x6B/\\x48-\\x4B/\ntr/h-\\x6B/H-\\x4B/\ntr/\\x68-k/\\x48-K/\n\ndo the same capitalizations as the previous example when run on ASCII platforms, but\nsomething completely different on EBCDIC ones.\n\nThe second class of portable ranges is invoked when one or both of the range's end points\nare expressed as \"\\N{...}\"\n\n$string =~ tr/\\N{U+20}-\\N{U+7E}//d;\n\nremoves from $string all the platform's characters which are equivalent to any of Unicode\nU+0020, U+0021, ... U+007D, U+007E. This is a portable range, and has the same effect on\nevery platform it is run on. In this example, these are the ASCII printable characters. So\nafter this is run, $string has only controls and characters which have no ASCII equivalents.\n\nBut, even for portable ranges, it is not generally obvious what is included without having\nto look things up in the manual. A sound principle is to use only ranges that both begin\nfrom, and end at, either ASCII alphabetics of equal case (\"b-e\", \"B-E\"), or digits (\"1-4\").\nAnything else is unclear (and unportable unless \"\\N{...}\" is used). If in doubt, spell out\nthe character sets in full.\n\nOptions:\n\nc   Complement the SEARCHLIST.\nd   Delete found but unreplaced characters.\nr   Return the modified string and leave the original string\nuntouched.\ns   Squash duplicate replaced characters.\n\nIf the \"/d\" modifier is specified, any characters specified by *SEARCHLIST* not found in\n*REPLACEMENTLIST* are deleted. (Note that this is slightly more flexible than the behavior\nof some tr programs, which delete anything they find in the *SEARCHLIST*, period.)\n\nIf the \"/s\" modifier is specified, sequences of characters, all in a row, that were\ntransliterated to the same character are squashed down to a single instance of that\ncharacter.\n\nmy $a = \"aaabbbca\";\n$a =~ tr/ab/dd/s;     # $a now is \"dcd\"\n\nIf the \"/d\" modifier is used, the *REPLACEMENTLIST* is always interpreted exactly as\nspecified. Otherwise, if the *REPLACEMENTLIST* is shorter than the *SEARCHLIST*, the final\ncharacter, if any, is replicated until it is long enough. There won't be a final character\nif and only if the *REPLACEMENTLIST* is empty, in which case *REPLACEMENTLIST* is copied\nfrom *SEARCHLIST*. An empty *REPLACEMENTLIST* is useful for counting characters in a class,\nor for squashing character sequences in a class.\n\ntr/abcd//            tr/abcd/abcd/\ntr/abcd/AB/          tr/abcd/ABBB/\ntr/abcd//d           s/[abcd]//g\ntr/abcd/AB/d         (tr/ab/AB/ + s/[cd]//g)  - but run together\n\nIf the \"/c\" modifier is specified, the characters to be transliterated are the ones NOT in\n*SEARCHLIST*, that is, it is complemented. If \"/d\" and/or \"/s\" are also specified, they\napply to the complemented *SEARCHLIST*. Recall, that if *REPLACEMENTLIST* is empty (except\nunder \"/d\") a copy of *SEARCHLIST* is used instead. That copy is made after complementing\nunder \"/c\". *SEARCHLIST* is sorted by code point order after complementing, and any\n*REPLACEMENTLIST* is applied to that sorted result. This means that under \"/c\", the order of\nthe characters specified in *SEARCHLIST* is irrelevant. This can lead to different results\non EBCDIC systems if *REPLACEMENTLIST* contains more than one character, hence it is\ngenerally non-portable to use \"/c\" with such a *REPLACEMENTLIST*.\n\nAnother way of describing the operation is this: If \"/c\" is specified, the *SEARCHLIST* is\nsorted by code point order, then complemented. If *REPLACEMENTLIST* is empty and \"/d\" is not\nspecified, *REPLACEMENTLIST* is replaced by a copy of *SEARCHLIST* (as modified under \"/c\"),\nand these potentially modified lists are used as the basis for what follows. Any character\nin the target string that isn't in *SEARCHLIST* is passed through unchanged. Every other\ncharacter in the target string is replaced by the character in *REPLACEMENTLIST* that\npositionally corresponds to its mate in *SEARCHLIST*, except that under \"/s\", the 2nd and\nfollowing characters are squeezed out in a sequence of characters in a row that all\ntranslate to the same character. If *SEARCHLIST* is longer than *REPLACEMENTLIST*,\ncharacters in the target string that match a character in *SEARCHLIST* that doesn't have a\ncorrespondence in *REPLACEMENTLIST* are either deleted from the target string if \"/d\" is\nspecified; or replaced by the final character in *REPLACEMENTLIST* if \"/d\" isn't specified.\n\nSome examples:\n\n$ARGV[1] =~ tr/A-Z/a-z/;   # canonicalize to lower case ASCII\n\n$cnt = tr/*/*/;            # count the stars in $\n$cnt = tr/*//;             # same thing\n\n$cnt = $sky =~ tr/*/*/;    # count the stars in $sky\n$cnt = $sky =~ tr/*//;     # same thing\n\n$cnt = $sky =~ tr/*//c;    # count all the non-stars in $sky\n$cnt = $sky =~ tr/*/*/c;   # same, but transliterate each non-star\n# into a star, leaving the already-stars\n# alone.  Afterwards, everything in $sky\n# is a star.\n\n$cnt = tr/0-9//;           # count the ASCII digits in $\n\ntr/a-zA-Z//s;              # bookkeeper -> bokeper\ntr/o/o/s;                  # bookkeeper -> bokkeeper\ntr/oe/oe/s;                # bookkeeper -> bokkeper\ntr/oe//s;                  # bookkeeper -> bokkeper\ntr/oe/o/s;                 # bookkeeper -> bokkopor\n\n($HOST = $host) =~ tr/a-z/A-Z/;\n$HOST = $host  =~ tr/a-z/A-Z/r; # same thing\n\n$HOST = $host =~ tr/a-z/A-Z/r   # chained with s///r\n=~ s/:/ -p/r;\n\ntr/a-zA-Z/ /cs;                 # change non-alphas to single space\n\n@stripped = map tr/a-zA-Z/ /csr, @original;\n# /r with map\n\ntr [\\200-\\377]\n[\\000-\\177];                 # wickedly delete 8th bit\n\n$foo !~ tr/A/a/    # transliterate all the A's in $foo to 'a',\n# return 0 if any were found and changed.\n# Otherwise return 1\n\nIf multiple transliterations are given for a character, only the first one is used:\n\ntr/AAA/XYZ/\n\nwill transliterate any A to X.\n\nBecause the transliteration table is built at compile time, neither the *SEARCHLIST* nor the\n*REPLACEMENTLIST* are subjected to double quote interpolation. That means that if you want\nto use variables, you must use an \"eval()\":\n\neval \"tr/$oldlist/$newlist/\";\ndie $@ if $@;\n\neval \"tr/$oldlist/$newlist/, 1\" or die $@;\n\n\"<<*EOF*\"\nA line-oriented form of quoting is based on the shell \"here-document\" syntax. Following a\n\"<<\" you specify a string to terminate the quoted material, and all lines following the\ncurrent line down to the terminating string are the value of the item.\n\nPrefixing the terminating string with a \"~\" specifies that you want to use \"Indented\nHere-docs\" (see below).\n\nThe terminating string may be either an identifier (a word), or some quoted text. An\nunquoted identifier works like double quotes. There may not be a space between the \"<<\" and\nthe identifier, unless the identifier is explicitly quoted. The terminating string must\nappear by itself (unquoted and with no surrounding whitespace) on the terminating line.\n\nIf the terminating string is quoted, the type of quotes used determine the treatment of the\ntext.\n\nDouble Quotes\nDouble quotes indicate that the text will be interpolated using exactly the same rules\nas normal double quoted strings.\n\nprint <<EOF;\nThe price is $Price.\nEOF\n\nprint << \"EOF\"; # same as above\nThe price is $Price.\nEOF\n\nSingle Quotes\nSingle quotes indicate the text is to be treated literally with no interpolation of its\ncontent. This is similar to single quoted strings except that backslashes have no\nspecial meaning, with \"\\\\\" being treated as two backslashes and not one as they would in\nevery other quoting construct.\n\nJust as in the shell, a backslashed bareword following the \"<<\" means the same thing as\na single-quoted string does:\n\n$cost = <<'VISTA';  # hasta la ...\nThat'll be $10 please, ma'am.\nVISTA\n\n$cost = <<\\VISTA;   # Same thing!\nThat'll be $10 please, ma'am.\nVISTA\n\nThis is the only form of quoting in perl where there is no need to worry about escaping\ncontent, something that code generators can and do make good use of.\n\nBackticks\nThe content of the here doc is treated just as it would be if the string were embedded\nin backticks. Thus the content is interpolated as though it were double quoted and then\nexecuted via the shell, with the results of the execution returned.\n\nprint << `EOC`; # execute command and get results\necho hi there\nEOC\n\nIndented Here-docs\nThe here-doc modifier \"~\" allows you to indent your here-docs to make the code more\nreadable:\n\nif ($somevar) {\nprint <<~EOF;\nThis is a here-doc\nEOF\n}\n\nThis will print...\n\nThis is a here-doc\n\n...with no leading whitespace.\n\nThe delimiter is used to determine the exact whitespace to remove from the beginning of\neach line. All lines must have at least the same starting whitespace (except lines only\ncontaining a newline) or perl will croak. Tabs and spaces can be mixed, but are matched\nexactly. One tab will not be equal to 8 spaces!\n\nAdditional beginning whitespace (beyond what preceded the delimiter) will be preserved:\n\nprint <<~EOF;\nThis text is not indented\nThis text is indented with two spaces\nThis text is indented with two tabs\nEOF\n\nFinally, the modifier may be used with all of the forms mentioned above:\n\n<<~\\EOF;\n<<~'EOF'\n<<~\"EOF\"\n<<~`EOF`\n\nAnd whitespace may be used between the \"~\" and quoted delimiters:\n\n<<~ 'EOF'; # ... \"EOF\", `EOF`\n\nIt is possible to stack multiple here-docs in a row:\n\nprint <<\"foo\", <<\"bar\"; # you can stack them\nI said foo.\nfoo\nI said bar.\nbar\n\nmyfunc(<< \"THIS\", 23, <<'THAT');\nHere's a line\nor two.\nTHIS\nand here's another.\nTHAT\n\nJust don't forget that you have to put a semicolon on the end to finish the statement, as\nPerl doesn't know you're not going to try to do this:\n\nprint <<ABC\n179231\nABC\n+ 20;\n\nIf you want to remove the line terminator from your here-docs, use \"chomp()\".\n\nchomp($string = <<'END');\nThis is a string.\nEND\n\nIf you want your here-docs to be indented with the rest of the code, use the \"<<~FOO\"\nconstruct described under \"Indented Here-docs\":\n\n$quote = <<~'FINIS';\nThe Road goes ever on and on,\ndown from the door where it began.\nFINIS\n\nIf you use a here-doc within a delimited construct, such as in \"s///eg\", the quoted material\nmust still come on the line following the \"<<FOO\" marker, which means it may be inside the\ndelimited construct:\n\ns/this/<<E . 'that'\nthe other\nE\n. 'more '/eg;\n\nIt works this way as of Perl 5.18. Historically, it was inconsistent, and you would have to\nwrite\n\ns/this/<<E . 'that'\n. 'more '/eg;\nthe other\nE\n\noutside of string evals.\n\nAdditionally, quoting rules for the end-of-string identifier are unrelated to Perl's quoting\nrules. \"q()\", \"qq()\", and the like are not supported in place of '' and \"\", and the only\ninterpolation is for backslashing the quoting character:\n\nprint << \"abc\\\"def\";\ntesting...\nabc\"def\n\nFinally, quoted strings cannot span multiple lines. The general rule is that the identifier\nmust be a string literal. Stick with that, and you should be safe.\n"
                },
                {
                    "name": "Gory details of parsing quoted constructs",
                    "content": "When presented with something that might have several different interpretations, Perl uses the\nDWIM (that's \"Do What I Mean\") principle to pick the most probable interpretation. This strategy\nis so successful that Perl programmers often do not suspect the ambivalence of what they write.\nBut from time to time, Perl's notions differ substantially from what the author honestly meant.\n\nThis section hopes to clarify how Perl handles quoted constructs. Although the most common\nreason to learn this is to unravel labyrinthine regular expressions, because the initial steps\nof parsing are the same for all quoting operators, they are all discussed together.\n\nThe most important Perl parsing rule is the first one discussed below: when processing a quoted\nconstruct, Perl first finds the end of that construct, then interprets its contents. If you\nunderstand this rule, you may skip the rest of this section on the first reading. The other\nrules are likely to contradict the user's expectations much less frequently than this first one.\n\nSome passes discussed below are performed concurrently, but because their results are the same,\nwe consider them individually. For different quoting constructs, Perl performs different numbers\nof passes, from one to four, but these passes are always performed in the same order.\n\nFinding the end\nThe first pass is finding the end of the quoted construct. This results in saving to a safe\nlocation a copy of the text (between the starting and ending delimiters), normalized as\nnecessary to avoid needing to know what the original delimiters were.\n\nIf the construct is a here-doc, the ending delimiter is a line that has a terminating string\nas the content. Therefore \"<<EOF\" is terminated by \"EOF\" immediately followed by \"\\n\" and\nstarting from the first column of the terminating line. When searching for the terminating\nline of a here-doc, nothing is skipped. In other words, lines after the here-doc syntax are\ncompared with the terminating string line by line.\n\nFor the constructs except here-docs, single characters are used as starting and ending\ndelimiters. If the starting delimiter is an opening punctuation (that is \"(\", \"[\", \"{\", or\n\"<\"), the ending delimiter is the corresponding closing punctuation (that is \")\", \"]\", \"}\",\nor \">\"). If the starting delimiter is an unpaired character like \"/\" or a closing\npunctuation, the ending delimiter is the same as the starting delimiter. Therefore a \"/\"\nterminates a \"qq//\" construct, while a \"]\" terminates both \"qq[]\" and \"qq]]\" constructs.\n\nWhen searching for single-character delimiters, escaped delimiters and \"\\\\\" are skipped. For\nexample, while searching for terminating \"/\", combinations of \"\\\\\" and \"\\/\" are skipped. If\nthe delimiters are bracketing, nested pairs are also skipped. For example, while searching\nfor a closing \"]\" paired with the opening \"[\", combinations of \"\\\\\", \"\\]\", and \"\\[\" are all\nskipped, and nested \"[\" and \"]\" are skipped as well. However, when backslashes are used as\nthe delimiters (like \"qq\\\\\" and \"tr\\\\\\\"), nothing is skipped. During the search for the end,\nbackslashes that escape delimiters or other backslashes are removed (exactly speaking, they\nare not copied to the safe location).\n\nFor constructs with three-part delimiters (\"s///\", \"y///\", and \"tr///\"), the search is\nrepeated once more. If the first delimiter is not an opening punctuation, the three\ndelimiters must be the same, such as \"s!!!\" and \"tr)))\", in which case the second delimiter\nterminates the left part and starts the right part at once. If the left part is delimited by\nbracketing punctuation (that is \"()\", \"[]\", \"{}\", or \"<>\"), the right part needs another\npair of delimiters such as \"s(){}\" and \"tr[]//\". In these cases, whitespace and comments are\nallowed between the two parts, although the comment must follow at least one whitespace\ncharacter; otherwise a character expected as the start of the comment may be regarded as the\nstarting delimiter of the right part.\n\nDuring this search no attention is paid to the semantics of the construct. Thus:\n\n\"$hash{\"$foo/$bar\"}\"\n\nor:\n\nm/\nbar       # NOT a comment, this slash / terminated m//!\n/x\n\ndo not form legal quoted expressions. The quoted part ends on the first \"\"\" and \"/\", and the\nrest happens to be a syntax error. Because the slash that terminated \"m//\" was followed by a\n\"SPACE\", the example above is not \"m//x\", but rather \"m//\" with no \"/x\" modifier. So the\nembedded \"#\" is interpreted as a literal \"#\".\n\nAlso no attention is paid to \"\\c\\\" (multichar control char syntax) during this search. Thus\nthe second \"\\\" in \"qq/\\c\\/\" is interpreted as a part of \"\\/\", and the following \"/\" is not\nrecognized as a delimiter. Instead, use \"\\034\" or \"\\x1c\" at the end of quoted constructs.\n\nInterpolation\nThe next step is interpolation in the text obtained, which is now delimiter-independent.\nThere are multiple cases.\n\n\"<<'EOF'\"\nNo interpolation is performed. Note that the combination \"\\\\\" is left intact, since\nescaped delimiters are not available for here-docs.\n\n\"m''\", the pattern of \"s'''\"\nNo interpolation is performed at this stage. Any backslashed sequences including \"\\\\\"\nare treated at the stage to \"parsing regular expressions\".\n\n'', \"q//\", \"tr'''\", \"y'''\", the replacement of \"s'''\"\nThe only interpolation is removal of \"\\\" from pairs of \"\\\\\". Therefore \"-\" in \"tr'''\"\nand \"y'''\" is treated literally as a hyphen and no character range is available. \"\\1\" in\nthe replacement of \"s'''\" does not work as $1.\n\n\"tr///\", \"y///\"\nNo variable interpolation occurs. String modifying combinations for case and quoting\nsuch as \"\\Q\", \"\\U\", and \"\\E\" are not recognized. The other escape sequences such as\n\"\\200\" and \"\\t\" and backslashed characters such as \"\\\\\" and \"\\-\" are converted to\nappropriate literals. The character \"-\" is treated specially and therefore \"\\-\" is\ntreated as a literal \"-\".\n\n\"\", ``, \"qq//\", \"qx//\", \"<file*glob>\", \"<<\"EOF\"\"\n\"\\Q\", \"\\U\", \"\\u\", \"\\L\", \"\\l\", \"\\F\" (possibly paired with \"\\E\") are converted to\ncorresponding Perl constructs. Thus, \"$foo\\Qbaz$bar\" is converted to\n\"$foo . (quotemeta(\"baz\" . $bar))\" internally. The other escape sequences such as \"\\200\"\nand \"\\t\" and backslashed characters such as \"\\\\\" and \"\\-\" are replaced with appropriate\nexpansions.\n\nLet it be stressed that *whatever falls between \"\\Q\" and \"\\E\"* is interpolated in the\nusual way. Something like \"\\Q\\\\E\" has no \"\\E\" inside. Instead, it has \"\\Q\", \"\\\\\", and\n\"E\", so the result is the same as for \"\\\\\\\\E\". As a general rule, backslashes between\n\"\\Q\" and \"\\E\" may lead to counterintuitive results. So, \"\\Q\\t\\E\" is converted to\n\"quotemeta(\"\\t\")\", which is the same as \"\\\\\\t\" (since TAB is not alphanumeric). Note\nalso that:\n\n$str = '\\t';\nreturn \"\\Q$str\";\n\nmay be closer to the conjectural *intention* of the writer of \"\\Q\\t\\E\".\n\nInterpolated scalars and arrays are converted internally to the \"join\" and \".\"\ncatenation operations. Thus, \"$foo XXX '@arr'\" becomes:\n\n$foo . \" XXX '\" . (join $\", @arr) . \"'\";\n\nAll operations above are performed simultaneously, left to right.\n\nBecause the result of \"\\Q *STRING* \\E\" has all metacharacters quoted, there is no way to\ninsert a literal \"$\" or \"@\" inside a \"\\Q\\E\" pair. If protected by \"\\\", \"$\" will be\nquoted to become \"\\\\\\$\"; if not, it is interpreted as the start of an interpolated\nscalar.\n\nNote also that the interpolation code needs to make a decision on where the interpolated\nscalar ends. For instance, whether \"a $x -> {c}\" really means:\n\n\"a \" . $x . \" -> {c}\";\n\nor:\n\n\"a \" . $x -> {c};\n\nMost of the time, the longest possible text that does not include spaces between\ncomponents and which contains matching braces or brackets. because the outcome may be\ndetermined by voting based on heuristic estimators, the result is not strictly\npredictable. Fortunately, it's usually correct for ambiguous cases.\n\nthe replacement of \"s///\"\nProcessing of \"\\Q\", \"\\U\", \"\\u\", \"\\L\", \"\\l\", \"\\F\" and interpolation happens as with\n\"qq//\" constructs.\n\nIt is at this step that \"\\1\" is begrudgingly converted to $1 in the replacement text of\n\"s///\", in order to correct the incorrigible *sed* hackers who haven't picked up the\nsaner idiom yet. A warning is emitted if the \"use warnings\" pragma or the -w\ncommand-line flag (that is, the $^W variable) was set.\n\n\"RE\" in \"m?RE?\", \"/RE/\", \"m/RE/\", \"s/RE/foo/\",\nProcessing of \"\\Q\", \"\\U\", \"\\u\", \"\\L\", \"\\l\", \"\\F\", \"\\E\", and interpolation happens\n(almost) as with \"qq//\" constructs.\n\nProcessing of \"\\N{...}\" is also done here, and compiled into an intermediate form for\nthe regex compiler. (This is because, as mentioned below, the regex compilation may be\ndone at execution time, and \"\\N{...}\" is a compile-time construct.)\n\nHowever any other combinations of \"\\\" followed by a character are not substituted but\nonly skipped, in order to parse them as regular expressions at the following step. As\n\"\\c\" is skipped at this step, \"@\" of \"\\c@\" in RE is possibly treated as an array symbol\n(for example @foo), even though the same text in \"qq//\" gives interpolation of \"\\c@\".\n\nCode blocks such as \"(?{BLOCK})\" are handled by temporarily passing control back to the\nperl parser, in a similar way that an interpolated array subscript expression such as\n\"foo$array[1+f(\"[xyz\")]bar\" would be.\n\nMoreover, inside \"(?{BLOCK})\", \"(?# comment )\", and a \"#\"-comment in a \"/x\"-regular\nexpression, no processing is performed whatsoever. This is the first step at which the\npresence of the \"/x\" modifier is relevant.\n\nInterpolation in patterns has several quirks: $|, $(, $), \"@+\" and \"@-\" are not\ninterpolated, and constructs $var[SOMETHING] are voted (by several different estimators)\nto be either an array element or $var followed by an RE alternative. This is where the\nnotation \"${arr[$bar]}\" comes handy: \"/${arr[0-9]}/\" is interpreted as array element -9,\nnot as a regular expression from the variable $arr followed by a digit, which would be\nthe interpretation of \"/$arr[0-9]/\". Since voting among different estimators may occur,\nthe result is not predictable.\n\nThe lack of processing of \"\\\\\" creates specific restrictions on the post-processed text.\nIf the delimiter is \"/\", one cannot get the combination \"\\/\" into the result of this\nstep. \"/\" will finish the regular expression, \"\\/\" will be stripped to \"/\" on the\nprevious step, and \"\\\\/\" will be left as is. Because \"/\" is equivalent to \"\\/\" inside a\nregular expression, this does not matter unless the delimiter happens to be character\nspecial to the RE engine, such as in \"s*foo*bar*\", \"m[foo]\", or \"m?foo?\"; or an\nalphanumeric char, as in:\n\nm m ^ a \\s* b mmx;\n\nIn the RE above, which is intentionally obfuscated for illustration, the delimiter is\n\"m\", the modifier is \"mx\", and after delimiter-removal the RE is the same as for\n\"m/ ^ a \\s* b /mx\". There's more than one reason you're encouraged to restrict your\ndelimiters to non-alphanumeric, non-whitespace choices.\n\nThis step is the last one for all constructs except regular expressions, which are processed\nfurther.\n\nparsing regular expressions\nPrevious steps were performed during the compilation of Perl code, but this one happens at\nrun time, although it may be optimized to be calculated at compile time if appropriate.\nAfter preprocessing described above, and possibly after evaluation if concatenation,\njoining, casing translation, or metaquoting are involved, the resulting *string* is passed\nto the RE engine for compilation.\n\nWhatever happens in the RE engine might be better discussed in perlre, but for the sake of\ncontinuity, we shall do so here.\n\nThis is another step where the presence of the \"/x\" modifier is relevant. The RE engine\nscans the string from left to right and converts it into a finite automaton.\n\nBackslashed characters are either replaced with corresponding literal strings (as with\n\"\\{\"), or else they generate special nodes in the finite automaton (as with \"\\b\").\nCharacters special to the RE engine (such as \"|\") generate corresponding nodes or groups of\nnodes. \"(?#...)\" comments are ignored. All the rest is either converted to literal strings\nto match, or else is ignored (as is whitespace and \"#\"-style comments if \"/x\" is present).\n\nParsing of the bracketed character class construct, \"[...]\", is rather different than the\nrule used for the rest of the pattern. The terminator of this construct is found using the\nsame rules as for finding the terminator of a \"{}\"-delimited construct, the only exception\nbeing that \"]\" immediately following \"[\" is treated as though preceded by a backslash.\n\nThe terminator of runtime \"(?{...})\" is found by temporarily switching control to the perl\nparser, which should stop at the point where the logically balancing terminating \"}\" is\nfound.\n\nIt is possible to inspect both the string given to RE engine and the resulting finite\nautomaton. See the arguments \"debug\"/\"debugcolor\" in the \"use re\" pragma, as well as Perl's\n-Dr command-line switch documented in \"Command Switches\" in perlrun.\n\nOptimization of regular expressions\nThis step is listed for completeness only. Since it does not change semantics, details of\nthis step are not documented and are subject to change without notice. This step is\nperformed over the finite automaton that was generated during the previous pass.\n\nIt is at this stage that \"split()\" silently optimizes \"/^/\" to mean \"/^/m\".\n\nI/O Operators\nThere are several I/O operators you should know about.\n\nA string enclosed by backticks (grave accents) first undergoes double-quote interpolation. It is\nthen interpreted as an external command, and the output of that command is the value of the\nbacktick string, like in a shell. In scalar context, a single string consisting of all output is\nreturned. In list context, a list of values is returned, one per line of output. (You can set $/\nto use a different line terminator.) The command is executed each time the pseudo-literal is\nevaluated. The status value of the command is returned in $? (see perlvar for the interpretation\nof $?). Unlike in csh, no translation is done on the return data--newlines remain newlines.\nUnlike in any of the shells, single quotes do not hide variable names in the command from\ninterpretation. To pass a literal dollar-sign through to the shell you need to hide it with a\nbackslash. The generalized form of backticks is \"qx//\", or you can call the \"readpipe\" in\nperlfunc function. (Because backticks always undergo shell expansion as well, see perlsec for\nsecurity concerns.)\n\nIn scalar context, evaluating a filehandle in angle brackets yields the next line from that file\n(the newline, if any, included), or \"undef\" at end-of-file or on error. When $/ is set to\n\"undef\" (sometimes known as file-slurp mode) and the file is empty, it returns '' the first\ntime, followed by \"undef\" subsequently.\n\nOrdinarily you must assign the returned value to a variable, but there is one situation where an\nautomatic assignment happens. If and only if the input symbol is the only thing inside the\nconditional of a \"while\" statement (even if disguised as a \"for(;;)\" loop), the value is\nautomatically assigned to the global variable $, destroying whatever was there previously.\n(This may seem like an odd thing to you, but you'll use the construct in almost every Perl\nscript you write.) The $ variable is not implicitly localized. You'll have to put a \"local $;\"\nbefore the loop if you want that to happen. Furthermore, if the input symbol or an explicit\nassignment of the input symbol to a scalar is used as a \"while\"/\"for\" condition, then the\ncondition actually tests for definedness of the expression's value, not for its regular truth\nvalue.\n\nThus the following lines are equivalent:\n\nwhile (defined($ = <STDIN>)) { print; }\nwhile ($ = <STDIN>) { print; }\nwhile (<STDIN>) { print; }\nfor (;<STDIN>;) { print; }\nprint while defined($ = <STDIN>);\nprint while ($ = <STDIN>);\nprint while <STDIN>;\n\nThis also behaves similarly, but assigns to a lexical variable instead of to $:\n\nwhile (my $line = <STDIN>) { print $line }\n\nIn these loop constructs, the assigned value (whether assignment is automatic or explicit) is\nthen tested to see whether it is defined. The defined test avoids problems where the line has a\nstring value that would be treated as false by Perl; for example a \"\" or a \"0\" with no trailing\nnewline. If you really mean for such values to terminate the loop, they should be tested for\nexplicitly:\n\nwhile (($ = <STDIN>) ne '0') { ... }\nwhile (<STDIN>) { last unless $; ... }\n\nIn other boolean contexts, \"<*FILEHANDLE*>\" without an explicit \"defined\" test or comparison\nelicits a warning if the \"use warnings\" pragma or the -w command-line switch (the $^W variable)\nis in effect.\n\nThe filehandles STDIN, STDOUT, and STDERR are predefined. (The filehandles \"stdin\", \"stdout\",\nand \"stderr\" will also work except in packages, where they would be interpreted as local\nidentifiers rather than global.) Additional filehandles may be created with the \"open()\"\nfunction, amongst others. See perlopentut and \"open\" in perlfunc for details on this.\n\nIf a \"<*FILEHANDLE*>\" is used in a context that is looking for a list, a list comprising all\ninput lines is returned, one line per list element. It's easy to grow to a rather large data\nspace this way, so use with care.\n\n\"<*FILEHANDLE*>\" may also be spelled \"readline(FILEHANDLE*)\". See \"readline\" in perlfunc.\n\nThe null filehandle \"<>\" (sometimes called the diamond operator) is special: it can be used to\nemulate the behavior of sed and awk, and any other Unix filter program that takes a list of\nfilenames, doing the same to each line of input from all of them. Input from \"<>\" comes either\nfrom standard input, or from each file listed on the command line. Here's how it works: the\nfirst time \"<>\" is evaluated, the @ARGV array is checked, and if it is empty, $ARGV[0] is set to\n\"-\", which when opened gives you standard input. The @ARGV array is then processed as a list of\nfilenames. The loop\n\nwhile (<>) {\n...                     # code for each line\n}\n\nis equivalent to the following Perl-like pseudo code:\n\nunshift(@ARGV, '-') unless @ARGV;\nwhile ($ARGV = shift) {\nopen(ARGV, $ARGV);\nwhile (<ARGV>) {\n...         # code for each line\n}\n}\n\nexcept that it isn't so cumbersome to say, and will actually work. It really does shift the\n@ARGV array and put the current filename into the $ARGV variable. It also uses filehandle *ARGV*\ninternally. \"<>\" is just a synonym for \"<ARGV>\", which is magical. (The pseudo code above\ndoesn't work because it treats \"<ARGV>\" as non-magical.)\n\nSince the null filehandle uses the two argument form of \"open\" in perlfunc it interprets special\ncharacters, so if you have a script like this:\n\nwhile (<>) {\nprint;\n}\n\nand call it with \"perl dangerous.pl 'rm -rfv *|'\", it actually opens a pipe, executes the \"rm\"\ncommand and reads \"rm\"'s output from that pipe. If you want all items in @ARGV to be interpreted\nas file names, you can use the module \"ARGV::readonly\" from CPAN, or use the double diamond\nbracket:\n\nwhile (<<>>) {\nprint;\n}\n\nUsing double angle brackets inside of a while causes the open to use the three argument form\n(with the second argument being \"<\"), so all arguments in \"ARGV\" are treated as literal\nfilenames (including \"-\"). (Note that for convenience, if you use \"<<>>\" and if @ARGV is empty,\nit will still read from the standard input.)\n\nYou can modify @ARGV before the first \"<>\" as long as the array ends up containing the list of\nfilenames you really want. Line numbers ($.) continue as though the input were one big happy\nfile. See the example in \"eof\" in perlfunc for how to reset line numbers on each file.\n\nIf you want to set @ARGV to your own list of files, go right ahead. This sets @ARGV to all plain\ntext files if no @ARGV was given:\n\n@ARGV = grep { -f && -T } glob('*') unless @ARGV;\n\nYou can even set them to pipe commands. For example, this automatically filters compressed\narguments through gzip:\n\n@ARGV = map { /\\.(gz|Z)$/ ? \"gzip -dc < $ |\" : $ } @ARGV;\n\nIf you want to pass switches into your script, you can use one of the \"Getopts\" modules or put a\nloop on the front like this:\n\nwhile ($ = $ARGV[0], /^-/) {\nshift;\nlast if /^--$/;\nif (/^-D(.*)/) { $debug = $1 }\nif (/^-v/)     { $verbose++  }\n# ...           # other switches\n}\n\nwhile (<>) {\n# ...           # code for each line\n}\n\nThe \"<>\" symbol will return \"undef\" for end-of-file only once. If you call it again after this,\nit will assume you are processing another @ARGV list, and if you haven't set @ARGV, will read\ninput from STDIN.\n\nIf what the angle brackets contain is a simple scalar variable (for example, $foo), then that\nvariable contains the name of the filehandle to input from, or its typeglob, or a reference to\nthe same. For example:\n\n$fh = \\*STDIN;\n$line = <$fh>;\n\nIf what's within the angle brackets is neither a filehandle nor a simple scalar variable\ncontaining a filehandle name, typeglob, or typeglob reference, it is interpreted as a filename\npattern to be globbed, and either a list of filenames or the next filename in the list is\nreturned, depending on context. This distinction is determined on syntactic grounds alone. That\nmeans \"<$x>\" is always a \"readline()\" from an indirect handle, but \"<$hash{key}>\" is always a\n\"glob()\". That's because $x is a simple scalar variable, but $hash{key} is not--it's a hash\nelement. Even \"<$x >\" (note the extra space) is treated as \"glob(\"$x \")\", not \"readline($x)\".\n\nOne level of double-quote interpretation is done first, but you can't say \"<$foo>\" because\nthat's an indirect filehandle as explained in the previous paragraph. (In older versions of\nPerl, programmers would insert curly brackets to force interpretation as a filename glob:\n\"<${foo}>\". These days, it's considered cleaner to call the internal function directly as\n\"glob($foo)\", which is probably the right way to have done it in the first place.) For example:\n\nwhile (<*.c>) {\nchmod 0644, $;\n}\n\nis roughly equivalent to:\n\nopen(FOO, \"echo *.c | tr -s ' \\t\\r\\f' '\\\\012\\\\012\\\\012\\\\012'|\");\nwhile (<FOO>) {\nchomp;\nchmod 0644, $;\n}\n\nexcept that the globbing is actually done internally using the standard \"File::Glob\" extension.\nOf course, the shortest way to do the above is:\n\nchmod 0644, <*.c>;\n\nA (file)glob evaluates its (embedded) argument only when it is starting a new list. All values\nmust be read before it will start over. In list context, this isn't important because you\nautomatically get them all anyway. However, in scalar context the operator returns the next\nvalue each time it's called, or \"undef\" when the list has run out. As with filehandle reads, an\nautomatic \"defined\" is generated when the glob occurs in the test part of a \"while\", because\nlegal glob returns (for example, a file called 0) would otherwise terminate the loop. Again,\n\"undef\" is returned only once. So if you're expecting a single value from a glob, it is much\nbetter to say\n\n($file) = <blurch*>;\n\nthan\n\n$file = <blurch*>;\n\nbecause the latter will alternate between returning a filename and returning false.\n\nIf you're trying to do variable interpolation, it's definitely better to use the \"glob()\"\nfunction, because the older notation can cause people to become confused with the indirect\nfilehandle notation.\n\n@files = glob(\"$dir/*.[ch]\");\n@files = glob($files[$i]);\n\nIf an angle-bracket-based globbing expression is used as the condition of a \"while\" or \"for\"\nloop, then it will be implicitly assigned to $. If either a globbing expression or an explicit\nassignment of a globbing expression to a scalar is used as a \"while\"/\"for\" condition, then the\ncondition actually tests for definedness of the expression's value, not for its regular truth\nvalue.\n"
                },
                {
                    "name": "Constant Folding",
                    "content": "Like C, Perl does a certain amount of expression evaluation at compile time whenever it\ndetermines that all arguments to an operator are static and have no side effects. In particular,\nstring concatenation happens at compile time between literals that don't do variable\nsubstitution. Backslash interpolation also happens at compile time. You can say\n\n'Now is the time for all'\n. \"\\n\"\n.  'good men to come to.'\n\nand this all reduces to one string internally. Likewise, if you say\n\nforeach $file (@filenames) {\nif (-s $file > 5 + 100 * 216) {  }\n}\n\nthe compiler precomputes the number which that expression represents so that the interpreter\nwon't have to.\n"
                },
                {
                    "name": "No-ops",
                    "content": "Perl doesn't officially have a no-op operator, but the bare constants 0 and 1 are special-cased\nnot to produce a warning in void context, so you can for example safely do\n\n1 while foo();\n"
                },
                {
                    "name": "Bitwise String Operators",
                    "content": "Bitstrings of any size may be manipulated by the bitwise operators (\"~ | & ^\").\n\nIf the operands to a binary bitwise op are strings of different sizes, | and ^ ops act as though\nthe shorter operand had additional zero bits on the right, while the & op acts as though the\nlonger operand were truncated to the length of the shorter. The granularity for such extension\nor truncation is one or more bytes.\n\n# ASCII-based examples\nprint \"j p \\n\" ^ \" a h\";            # prints \"JAPH\\n\"\nprint \"JA\" | \"  ph\\n\";              # prints \"japh\\n\"\nprint \"japh\\nJunk\" & '';       # prints \"JAPH\\n\";\nprint 'p N$' ^ \" E<H\\n\";            # prints \"Perl\\n\";\n\nIf you are intending to manipulate bitstrings, be certain that you're supplying bitstrings: If\nan operand is a number, that will imply a numeric bitwise operation. You may explicitly show\nwhich type of operation you intend by using \"\" or \"0+\", as in the examples below.\n\n$foo =  150  |  105;        # yields 255  (0x96 | 0x69 is 0xFF)\n$foo = '150' |  105;        # yields 255\n$foo =  150  | '105';       # yields 255\n$foo = '150' | '105';       # yields string '155' (under ASCII)\n\n$baz = 0+$foo & 0+$bar;     # both ops explicitly numeric\n$biz = \"$foo\" ^ \"$bar\";     # both ops explicitly stringy\n\nThis somewhat unpredictable behavior can be avoided with the \"bitwise\" feature, new in Perl\n5.22. You can enable it via \"use feature 'bitwise'\" or \"use v5.28\". Before Perl 5.28, it used to\nemit a warning in the \"experimental::bitwise\" category. Under this feature, the four standard\nbitwise operators (\"~ | & ^\") are always numeric. Adding a dot after each operator (\"~. |. &.\n^.\") forces it to treat its operands as strings:\n\nuse feature \"bitwise\";\n$foo =  150  |  105;        # yields 255  (0x96 | 0x69 is 0xFF)\n$foo = '150' |  105;        # yields 255\n$foo =  150  | '105';       # yields 255\n$foo = '150' | '105';       # yields 255\n$foo =  150  |. 105;        # yields string '155'\n$foo = '150' |. 105;        # yields string '155'\n$foo =  150  |.'105';       # yields string '155'\n$foo = '150' |.'105';       # yields string '155'\n\n$baz = $foo &  $bar;        # both operands numeric\n$biz = $foo ^. $bar;        # both operands stringy\n\nThe assignment variants of these operators (\"&= |= ^= &.= |.= ^.=\") behave likewise under the\nfeature.\n\nIt is a fatal error if an operand contains a character whose ordinal value is above 0xFF, and\nhence not expressible except in UTF-8. The operation is performed on a non-UTF-8 copy for other\noperands encoded in UTF-8. See \"Byte and Character Semantics\" in perlunicode.\n\nSee \"vec\" in perlfunc for information on how to manipulate individual bits in a bit vector.\n"
                },
                {
                    "name": "Integer Arithmetic",
                    "content": "By default, Perl assumes that it must do most of its arithmetic in floating point. But by saying\n\nuse integer;\n\nyou may tell the compiler to use integer operations (see integer for a detailed explanation)\nfrom here to the end of the enclosing BLOCK. An inner BLOCK may countermand this by saying\n\nno integer;\n\nwhich lasts until the end of that BLOCK. Note that this doesn't mean everything is an integer,\nmerely that Perl will use integer operations for arithmetic, comparison, and bitwise operators.\nFor example, even under \"use integer\", if you take the sqrt(2), you'll still get 1.4142135623731\nor so.\n\nUsed on numbers, the bitwise operators (\"&\" \"|\" \"^\" \"~\" \"<<\" \">>\") always produce integral\nresults. (But see also \"Bitwise String Operators\".) However, \"use integer\" still has meaning for\nthem. By default, their results are interpreted as unsigned integers, but if \"use integer\" is in\neffect, their results are interpreted as signed integers. For example, \"~0\" usually evaluates to\na large integral value. However, \"use integer; ~0\" is -1 on two's-complement machines.\n"
                },
                {
                    "name": "Floating-point Arithmetic",
                    "content": "While \"use integer\" provides integer-only arithmetic, there is no analogous mechanism to provide\nautomatic rounding or truncation to a certain number of decimal places. For rounding to a\ncertain number of digits, \"sprintf()\" or \"printf()\" is usually the easiest route. See perlfaq4.\n\nFloating-point numbers are only approximations to what a mathematician would call real numbers.\nThere are infinitely more reals than floats, so some corners must be cut. For example:\n\nprintf \"%.20g\\n\", 123456789123456789;\n#        produces 123456789123456784\n\nTesting for exact floating-point equality or inequality is not a good idea. Here's a (relatively\nexpensive) work-around to compare whether two floating-point numbers are equal to a particular\nnumber of decimal places. See Knuth, volume II, for a more robust treatment of this topic.\n\nsub fpequal {\nmy ($X, $Y, $POINTS) = @;\nmy ($tX, $tY);\n$tX = sprintf(\"%.${POINTS}g\", $X);\n$tY = sprintf(\"%.${POINTS}g\", $Y);\nreturn $tX eq $tY;\n}\n\nThe POSIX module (part of the standard perl distribution) implements \"ceil()\", \"floor()\", and\nother mathematical and trigonometric functions. The \"Math::Complex\" module (part of the standard\nperl distribution) defines mathematical functions that work on both the reals and the imaginary\nnumbers. \"Math::Complex\" is not as efficient as POSIX, but POSIX can't work with complex\nnumbers.\n\nRounding in financial applications can have serious implications, and the rounding method used\nshould be specified precisely. In these cases, it probably pays not to trust whichever system\nrounding is being used by Perl, but to instead implement the rounding function you need\nyourself.\n"
                },
                {
                    "name": "Bigger Numbers",
                    "content": "The standard \"Math::BigInt\", \"Math::BigRat\", and \"Math::BigFloat\" modules, along with the\n\"bignum\", \"bigint\", and \"bigrat\" pragmas, provide variable-precision arithmetic and overloaded\noperators, although they're currently pretty slow. At the cost of some space and considerable\nspeed, they avoid the normal pitfalls associated with limited-precision representations.\n\nuse 5.010;\nuse bigint;  # easy interface to Math::BigInt\n$x = 123456789123456789;\nsay $x * $x;\n+15241578780673678515622620750190521\n\nOr with rationals:\n\nuse 5.010;\nuse bigrat;\n$x = 3/22;\n$y = 4/6;\nsay \"x/y is \", $x/$y;\nsay \"x*y is \", $x*$y;\nx/y is 9/44\nx*y is 1/11\n\nSeveral modules let you calculate with unlimited or fixed precision (bound only by memory and\nCPU time). There are also some non-standard modules that provide faster implementations via\nexternal C libraries.\n\nHere is a short, but incomplete summary:\n\nMath::String           treat string sequences like numbers\nMath::FixedPrecision   calculate with a fixed precision\nMath::Currency         for currency calculations\nBit::Vector            manipulate bit vectors fast (uses C)\nMath::BigIntFast       Bit::Vector wrapper for big numbers\nMath::Pari             provides access to the Pari C library\nMath::Cephes           uses the external Cephes C library (no\nbig numbers)\nMath::Cephes::Fraction fractions via the Cephes library\nMath::GMP              another one using an external C library\nMath::GMPz             an alternative interface to libgmp's big ints\nMath::GMPq             an interface to libgmp's fraction numbers\nMath::GMPf             an interface to libgmp's floating point numbers\n\nChoose wisely.\n"
                }
            ]
        }
    },
    "summary": "perlop - Perl operators and precedence",
    "flags": [],
    "examples": [],
    "see_also": []
}