Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

3586 lines (3481 sloc) 151.129 kb
<!doctype html>
<html>
<head>
<title>perlopquick</title>
</head>
<body>
<h1>PRECEDENCE</h1>
<pre>
Associativity Precedence
left terms and list operators (leftward)
left -&gt;
nonassoc ++ --
right **
right ! ~ \ and unary + and -
left =~ !~
left * / % x
left + - .
left &lt;&lt; &gt;&gt;
nonassoc named unary operators, filetest operators
nonassoc &lt; &gt; &lt;= &gt;= lt gt le ge
nonassoc == != &lt;=&gt; eq ne cmp ~~
left &amp;
left | ^
left &amp;&amp;
left || //
nonassoc .. ...
right ?:
right = += -= *= etc.
left , =&gt;
nonassoc list operators (rightward)
right not
left and
left or xor
</pre>
<h1>OPERATORS</h1>
<h2 id="%22X%22">"X"</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a> and <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the double quote operator (aka the interpolating string operator). It creates a string literal out of X. If a scalar, array, or an index into a array or hash is in X, the value of that variable is inserted into the string in place if the variable. Arrays are formated using <code>$&quot;</code>:
</p>
<pre>
my $interpolated_value = join $&quot;, @array;
</pre>
<p>
To place a <code>&quot;</code> inside the string, you must escape it with <code>\</code>:
</p>
<pre>
my $quote = &quot;He said \&quot;I like quotes.\&quot;&quot;;
</pre>
<p>
There are many special escapes such as <code>\t</code> for tab and <code>\n</code> for newline, as well as a generalized form of escape that uses Unicode ordinal numbers:
</p>
<pre>
my $string = &quot;Please provide references with your r\x{e9}sum\x{e9}.&quot;;
</pre>
<p>
Here <code>\x{e9}</code> creates the character associated with the ordinal number 233 (0xe9 in hexadecimal) in Unicode: LATIN SMALL LETTER E WITH ACUTE.
</p>
<p>
For a full discussion of how strings work, see <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>.
</p>
<h3>Example</h3>
<pre>
my $name = &quot;World&quot;;
my $string = &quot;Hello, $name!\n&quot;; #$string is now &quot;Hello World!\n&quot;;
</pre>
<h3>See also</h3>
<p>
<a href="#qq(X)">qq(X)</a>, <a href="#'X'">'X'</a>, <a href="#q(X)">q(X)</a>, <a href="http://perldoc.perl.org/perlvar.html#$%22"><em>$&quot;</em> in perlvar</a>, and <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>
</p>
<h2 id="qq(X)">qq(X)</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a> and <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the generalized double quote operator (aka the generalized interpolating string operator). It creates a string literal out of X. If a scalar, array, or an index into a array or hash is in X, the value of that variable is inserted into the string in place if the variable. Arrays are formated using <code>$&quot;</code>:
</p>
<pre>
my $interpolated_value = join $&quot;, @array;
</pre>
<p>
The delimiters <code>()</code> are chosen by the user and may consist of either bracketing characters (<code>qq&lt;&gt;</code>, <code>qq()</code>, <code>qq{}</code>, and <code>qq[]</code>) or matching characters (<code>qq##</code>, <code>qqaa</code>, etc.). It is generally used to allow the user to avoid having to escape characters:
</p>
<pre>
my $quote = qq/He said &quot;I like quotes.&quot;/;
</pre>
<p>
If the delimiter is not a bracketing pair, or if the brackets are unbalanced, you will need to escape the delimiter with <code>\</code> if you wish to have that character in the string:
</p>
<pre>
my $quote = qq{I have too many \} characters};
</pre>
<p>
But it is often better to just choose a delimiter that does not conflict with the string:
</p>
<pre>
my $better = qq/I have too many } characters/;
</pre>
<p>
There are many special escapes such as <code>\t</code> for tab and <code>\n</code> for newline, as well as a generalized form of escape that uses Unicode ordinal numbers:
</p>
<pre>
my $string = qq{provide references with your r\x{e9}sum\x{e9}.};
</pre>
<p>
Here <code>\x{e9}</code> creates the character associated with the ordinal number 233 (0xe9 in hexadecimal) in Unicode: LATIN SMALL LETTER E WITH ACUTE.
</p>
<p>
For a full discussion of how strings work, see <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>.
</p>
<h3>Example</h3>
<pre>
my $name = &quot;World&quot;;
my $string = qq/Hello, $name!\n/; #$string is now &quot;Hello World!\n&quot;;
</pre>
<h3>See also</h3>
<p>
<a href="#q(X)">q(X)</a>, <a href="#'X'">'X'</a> <a href="#%22X%22">"X"</a>, <a href="http://perldoc.perl.org/perlvar.html#$%22"><em>$&quot;</em> in perlvar</a>, and <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>
</p>
<h2 id="'X'">'X'</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a> and <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the single quote operator (aka the non-interpolating string operator). It creates a string literal out of X.
</p>
<p>
To place a <code>&#39;</code> inside the string, you must escape it with <code>\</code>:
</p>
<pre>
my $quote = &#39;He said \&#39;I like quotes.\&#39;&#39;;
</pre>
<p>
To place a <code>\</code> inside the string, you may escape it with another <code>\</code>:
</p>
<pre>
my $quote = &#39;This is a backslash: \\&#39;;
</pre>
<p>
but this is only necessary when the <code>\</code> is followed by the closing single quote. Unlike double quoted strings, single quoted strings only recognize those two escape sequences
</p>
<p>
For a full discussion of how strings work, see <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>.
</p>
<h3>Example</h3>
<pre>
my $name = &#39;World&#39;;
my $string = &#39;Hello, $name!\n&#39;; #$string is now &quot;Hello \$name!\n&quot;;
</pre>
<h3>See also</h3>
<p>
<a href="#%22X%22">"X"</a>, <a href="#qq(X)">qq(X)</a>, <a href="#q(X)">q(X)</a>, <a href="http://perldoc.perl.org/perlvar.html#$%22"><em>$&quot;</em> in perlvar</a>, and <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>
</p>
<h2 id="q(X)">q(X)</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a> and <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the generalized single quote operator (aka the generalized non-interpolating string operator). It creates a string literal out of X.
</p>
<p>
The delimiters <code>()</code> are chosen by the user and may consist of either bracketing characters (<code>q&lt;&gt;</code>, <code>q()</code>, <code>q{}</code>, and <code>q[]</code>) or matching characters (<code>q##</code>, <code>qaa</code>, etc.). It is generally used to allow the user to avoid having to escape characters:
</p>
<pre>
my $quote = q/He said &#39;I like quotes.&#39;/;
</pre>
<p>
If the delimiter is not a bracketing pair, or if the brackets are unbalanced, you will need to escape the delimiter with <code>\</code> if you wish to have that character in the string:
</p>
<pre>
my $quote = q{I have too many \} characters};
</pre>
<p>
But it is often better to just choose a delimiter that does not conflict with the string:
</p>
<pre>
my $better = q/I have too many } characters/;
</pre>
<p>
Unlike double quoted strings, the escaping of the delimiter is the only escape.
</p>
<p>
For a full discussion of how strings work, see <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>.
</p>
<h3>Example</h3>
<pre>
my $name = &quot;World&quot;;
my $string = q/Hello, $name!\n/; #$string is now &quot;Hello \$name!\n&quot;;
</pre>
<h3>See also</h3>
<p>
<a href="#%22X%22">"X"</a>, <a href="#'X'">'X'</a>, <a href="#qq(X)">qq(X)</a>, <a href="http://perldoc.perl.org/perlvar.html#$%22"><em>$&quot;</em> in perlvar</a>, and <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>
</p>
<h2 id="qw(X)">qw(X)</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a> and <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the quote word operator. It creates a list of strings. The individual strings are whitespace separated. It does not interpolate.
</p>
<p>
The delimiters <code>()</code> are chosen by the user and may consist of either bracketing characters (<code>qw&lt;&gt;</code>, <code>qw()</code>, <code>qw{}</code>, and <code>qw[]</code>) or matching characters (<code>qw##</code>, <code>qwaa</code>, etc.). It is generally used to allow the user to avoid having to escape characters:
</p>
<pre>
my @list = qw/&#39;a&#39; &#39;b&#39; &#39;c&#39;/; #@list is now (&quot;&#39;a&#39;&quot;, &quot;&#39;b&#39;&quot;, &quot;&#39;c&#39;&quot;)
</pre>
<p>
If the delimiter is not a bracketing pair, or if the brackets are unbalanced, you will need to escape the delimiter with <code>\</code> if you wish to have that character in the string:
</p>
<pre>
my @broken = qw{I have too many } characters}; #broken
my @works = qw{I have too many \} characters}; #works
my @balanced = qw{this works {} because it is balanced} #works
</pre>
<p>
But it is often better to just choose a delimiter that does not conflict with the string:
</p>
<pre>
my $better = qw/I have too many } characters/;
</pre>
<p>
Unlike double quoted strings, the escaping of the delimiter is the only escape.
</p>
<h3>Example</h3>
<pre>
my @a = qw/ a b c /; #@a is now (&quot;a&quot;, &quot;b&quot;, &quot;c&quot;)
my @b = qw/ $foo $bar /; #@b is now (&#39;$foo&#39;, &#39;$bar&#39;)
</pre>
<h3>See Also</h3>
<p>
<a href="#'X'">'X'</a>, <a href="#q(X)">q(X)</a>, and <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>
</p>
<h2 id="X[Y]">X[Y]</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a> and <a href="http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators"><em>Quote and Quote-like Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the array index operator. Indexes are <code>0</code> based (unless <code>$[</code> has been set to a non-zero value). Negative indexes count backwards from the end of the list or array.
</p>
<p>
If X&#39;s sigil is <code>$</code>, then the expression Y is placed in scalar context when it is evaluated and then treated as a number, so, it is converted to a number before it is used. If it cannot be converted then it is turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on). It returns the Yth item from X.
</p>
<p>
If X&#39;s sigil is <code>@</code> instead, then the expression Y is placed in list context when it is evaluated and each item in the resulting list is then treated as a number, so, they are converted to a number before it is used. Each one will be turned into <code>0</code> if it cannot be converted (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on). It returns a list of items from the array X at the indexes in the list generated by Y.
</p>
<h3>Example</h3>
<pre>
my @a = (&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;);
my $x = $a[2]; #$x is now equal to &quot;c&quot;
my $y = $a[-3]; #$y is now equal to &quot;b&quot;
my @b = @a[1, 2]; #@b is now (&quot;b&quot;, &quot;c&quot;)
$a[2] = &#39;e&#39;; #@a is now (&#39;a&#39;, &#39;b&#39;, &#39;e&#39;, &#39;d&#39;)
@b[0, 1] = @b[1, 0]; #swap values @b is now (&#39;c&#39;, &#39;b&#39;)
</pre>
<h3>See also</h3>
<p>
<a href="#(X)[Y]">(X)[Y]</a> and <a href="#X->[Y]">X->[Y]</a>
</p>
<h2 id="(X)[Y]">(X)[Y]</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the list index operator. The expression Y is placed in list context when it is evaluated and each item in the resulting list is then treated as a number, so, they are converted to a number before it is used. Each one will be turned into <code>0</code> if it cannot be converted (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on). It returns a list of items from the list X at the indexes in the list generated by Y.
</p>
<h3>Example</h3>
<pre>
my $i = 4;
my $x = (&quot;a&quot; .. &quot;z&quot;)[$i]; #$x is now &quot;e&quot;
my $y = (&quot;a&quot; .. &quot;z&quot;)[-$i]; #$y is now &quot;w&quot;
my @a = (&quot;a&quot; .. &quot;z&quot;)[0 .. $i]; #@a is now (&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;)
my @b = (&quot;a&quot; .. &quot;z&quot;)[1, 0, 3]; #@b is now (&quot;b&quot;, &quot;a&quot;, &quot;d&quot;)
</pre>
<h3>See also</h3>
<p>
<a href="#(X)[Y]">(X)[Y]</a>
</p>
<h2 id="X{Y}">X{Y}</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the hash index operator. It retrieves the value associated with the key Y from X. If Y is a list of keys then a slice is returned (see <a href="http://perldoc.perl.org/perldata.html#">perldata</a> for information about slices).
</p>
<h3>Example</h3>
<pre>
my %h = (a =&gt; 1, b =&gt; 2, c =&gt; 3);
my $x = $h{c}; #$x is now 3
my @a = @h{&quot;a&quot;, &quot;b&quot;}; #@a is now (1, 2)
$h{d} = 4; #%h is now (a =&gt; 1, b =&gt; 2, c =&gt; 3, d =&gt; 4)
@h{qw/a d/} = (0, 1); #%h is now (a =&gt; 0, b =&gt; 1, c =&gt; 3, d =&gt; 4)
</pre>
<h3>See also</h3>
<p>
<a href="#(X){Y}">(X){Y}</a> and <a href="#X->{Y}">X->{Y}</a>
</p>
<h2 id="X->[Y]">X->[Y]</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#The-Arrow-Operator"><em>The Arrow Operator</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the infix array dereferencing operator (AKA The Arrow Operator). It fetches the value at position Y in an array reference returned by the expression X. When dealing with multiple levels of dereferencing (such as with a reference to an array of arrays) only the first level requires the arrow operator.
</p>
<p>
If X does not evaluate to an array reference, then a runtime error occurs.
</p>
<h3>Example</h3>
<pre>
my @a = (&quot;a&quot;, &quot;b&quot;, &quot;c&quot;);
my $aref = \@a;
my $x = $aref-&gt;[1]; #$x is now &quot;b&quot;
$aref-&gt;[4] = &quot;d&quot;; #@a is now (&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;)
my $aoa = [
[0, 1, 2 ],
[&quot;a&quot;, &quot;b&quot;, &quot;c&quot;],
];
my $y = $aoa-&gt;[1][1]; #$y is now &quot;b&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#\X">\X</a>, <a href="#@{X}">@{X}</a>, <a href="#${X}[Y]">${X}[Y]</a>, <a href="http://perldoc.perl.org/perlreftut.html#">perlreftut</a>, and <a href="http://perldoc.perl.org/perlref.html#">perlref</a>
</p>
<h2 id="X->{Y}">X->{Y}</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#The-Arrow-Operator"><em>The Arrow Operator</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the infix hash dereferencing operator (AKA The Arrow Operator). It fetches the value associated with the key Y in a hash reference returned by the expression X. When dealing with multiple levels of dereferencing (such as with a reference to a hash of hashes) only the first level requires the arrow operator.
</p>
<p>
If X does not evaluate to a hash reference, then a runtime error occurs.
</p>
<h3>Example</h3>
<pre>
my %h = (a =&gt; 1, b =&gt; 2, c =&gt; 3);
my $href = \%h;
my $x = $href-&gt;{b}; #$x is now 2
$href-&gt;{d} = 4; #%h is now (a =&gt; 1, b =&gt; 2, c =&gt; 3, d =&gt; 4)
my $hoh = {
a =&gt; { a =&gt; 1, b =&gt; 2, c =&gt; 3 }
b =&gt; { a =&gt; 4, b =&gt; 5, c =&gt; 6 }
};
my $y = $hoh-&gt;{a}{b}; #$y is now 2
</pre>
<h3>See also</h3>
<p>
<a href="#\X">\X</a>, <a href="#%{X}">%{X}</a>, <a href="#${X}{Y}">${X}{Y}</a>, <a href="http://perldoc.perl.org/perlreftut.html#">perlreftut</a>, and <a href="http://perldoc.perl.org/perlref.html#">perlref</a>
</p>
<h2 id="X->(Y)">X->(Y)</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#The-Arrow-Operator"><em>The Arrow Operator</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the infix dereferencing function call operator (AKA The Arrow Operator). It calls the function referred to by X with the arguments Y. When dealing with multiple levels of dereferencing (such as with a reference to a hash of functions) only the first level requires the arrow operator; however, it is recommended you do not use this feature as it tends to cause confusion.
</p>
<p>
If X does not evaluate to a code reference, then a runtime error occurs.
</p>
<h3>Example</h3>
<pre>
my $sub = sub {
my ($arg1, $arg2, $arg3) = @_;
print &quot;$arg1 = $arg2 + $arg3\n&quot;;
};
my $href = {
func =&gt; $sub,
};
$sub-&gt;(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;); #prints &quot;a = b + c\n&quot;
$href-&gt;{func}(1, 2, 3); #prints &quot;1 = 2 + 3\n&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#\X">\X</a>, <a href="http://perldoc.perl.org/perlsub.html#">perlsub</a>, <a href="http://perldoc.perl.org/perlreftut.html#">perlreftut</a>, and <a href="http://perldoc.perl.org/perlref.html#">perlref</a>
</p>
<h2 id="${X}">${X}</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
If X is the name of a scalar variable, then this is just another way of saying <code>$X</code>. This form is handy during interpolation when the name of a variable would be ambiguous:
</p>
<pre>
my $base = &quot;foo&quot;;
my $s = &quot;${base}bar&quot;; #$s is now &quot;foobar&quot;
</pre>
<p>
When X is an expression, this is the scalar dereferencing operator. If X evaluates to a scalar reference then the value of the referenced item it returned. If X does not evaluate to a scalar reference a runtime error occurs. If X is a simple scalar variable the braces are unnecessary.
</p>
<p>
If strict is turned off, and it shouldn&#39;t be, and X evaluates to a string then <code>${X}</code> returns a scalar variable whose name is the same as the string.
</p>
<h3>Example</h3>
<pre>
my $x = 5;
my $sref = \$x;
my @a = ($sref);
$$sref = 6; #$x is now 6
${$a[0]} = 7; #$x is now 7
no strict &quot;refs&quot;;
my $bad = &quot;x&quot;;
$$bad = 8; #$x is now 8
</pre>
<h3>See also</h3>
<p>
<a href="#\X">\X</a>, <a href="http://perldoc.perl.org/perlreftut.html#">perlreftut</a>, and <a href="http://perldoc.perl.org/perlref.html#">perlref</a>
</p>
<h2 id="${X}[Y]">${X}[Y]</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
If X is the name of an array variable, then this is just another way of saying <code>$X[Y]</code>.
</p>
<p>
When X is an expression, this is the indexing array dereferencing operator. If X evaluates to an array reference then it returns value of the Yth item of the referenced array. If X does not evaluate to an array reference a runtime error occurs. If X is a simple scalar variable the braces are unnecessary. The use of this operator is discouraged, see the <a href="#X->[Y]">X->[Y]</a> operator for a better solution.
</p>
<p>
If strict is turned off, and it shouldn&#39;t be, and X evaluates to a string then <code>${X}[Y]</code> returns the Yth item from the array whose name is the same as the string.
</p>
<h3>Example</h3>
<pre>
my @a = qw(a b c);
my $aref = \@a;
${$aref}[0] = 1; #@a is now (1, &quot;b&quot;, &quot;c&quot;);
no strict &quot;refs&quot;;
my $bad = &quot;a&quot;;
${$bad}[5] = &quot;d&quot;; #@a is now (1, &quot;b&quot;, &quot;c&quot;, undef, undef, &quot;d&quot;)
</pre>
<h3>See also</h3>
<p>
<a href="#\X">\X</a>, <a href="#X->[Y]">X->[Y]</a>, <a href="http://perldoc.perl.org/perlreftut.html#">perlreftut</a>, and <a href="http://perldoc.perl.org/perlref.html#">perlref</a>
</p>
<h2 id="${X}{Y}">${X}{Y}</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
If X is the name of a hash variable, then this is just another way of saying <code>$X{Y}</code>.
</p>
<p>
When X is an expression, this is the indexing hash dereferencing operator. If X evaluates to an hash reference then it returns value associated with the key Y of the referenced hash. If X does not evaluate to an hash reference a runtime error occurs. If X is a simple scalar variable the braces are unnecessary. The use of this operator is discouraged, see the <a href="#X->{Y}">X->{Y}</a> operator for a better solution.
</p>
<p>
If strict is turned off, and it shouldn&#39;t be, and X evaluates to a string then <code>${X}{Y}</code> returns the value associated with the key Y from the hash whose name is the same as the string.
</p>
<h3>Example</h3>
<pre>
my %h = (a =&gt; 1, b =&gt; 2, c =&gt; 3);
my $href = \%h;
${$href}{a} = 4; #%h is now (a =&gt; 4, b =&gt; 2, c =&gt; 3);
no strict &quot;refs&quot;;
my $bad = &quot;h&quot;;
${$bad}{d} = 4; #%h is now (a =&gt; 4, b =&gt; 2, c =&gt; 3, d =&gt; 4);
</pre>
<h3>See also</h3>
<p>
<a href="#\X">\X</a>, <a href="#X->{Y}">X->{Y}</a>, <a href="http://perldoc.perl.org/perlreftut.html#">perlreftut</a>, and <a href="http://perldoc.perl.org/perlref.html#">perlref</a>
</p>
<h2 id="@{X}">@{X}</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
If X is the name of an array variable then this is just another way of saying @X. This form is handy during interpolation when the name of a variable would be ambiguous:
</p>
<pre>
my @a = (1 .. 5);
my $x = &quot;@{a}bar&quot;; #$x is now &quot;1 2 3bar&quot;
</pre>
<p>
When X is an expression, this is the array dereferencing operator. If X evaluates to a array reference then the value of the referenced item is returned. If X does not evaluate to a array reference a runtime error occurs. If X is a simple scalar variable the braces are unnecessary.
</p>
<p>
If strict is turned off, and it shouldn&#39;t be, and X evaluates to a string then @{X} returns an array variable whose name is the same as the string.
</p>
<h3>Example</h3>
<pre>
my @a;
my $aref = \@a;
my @b = ($aref);
@$aref = (1, 2, 3); #@a is now (1, 2, 3)
@{$b[0]} = (4, 5, 6); #@a is now (4, 5, 6)
no strict &quot;refs&quot;;
my $bad = &quot;a&quot;;
@{$bad}[0,1] = 8; #$x is now 8
</pre>
<h3>See also</h3>
<p>
<a href="#\X">\X</a>, <a href="http://perldoc.perl.org/perlreftut.html#">perlreftut</a>, and <a href="http://perldoc.perl.org/perlref.html#">perlref</a>
</p>
<h2 id="%{X}">%{X}</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Terms-and-List-Operators-(Leftward)"><em>Terms and List Operators (Leftward)</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
If X is the name of an array variable then this is just another way of saying %X.
</p>
<p>
When X is an expression, this is the hash dereferencing operator. If X evaluates to a hash reference then the value of the referenced item is returned. If X does not evaluate to a hash reference a runtime error occurs. If X is a simple scalar variable the braces are unnecessary.
</p>
<p>
If strict is turned off, and it shouldn&#39;t be, and X evaluates to a string then @{X} returns an array variable whose name is the same as the string.
</p>
<h3>Example</h3>
<pre>
my %h;
my $href = \%h;
my @a = ($href);
%$href = (a =&gt; 1); #%h is now (a =&gt; 1)
no strict &quot;refs&quot;;
my $bad = &quot;h&quot;;
@{$bad}{&quot;c&quot;, &quot;d&quot;} = (3, 4); #%h is now (a =&gt; 1, c =&gt; 3, d =&gt; 4)
</pre>
<h3>See also</h3>
<p>
<a href="#\X">\X</a>, <a href="http://perldoc.perl.org/perlreftut.html#">perlreftut</a>, and <a href="http://perldoc.perl.org/perlref.html#">perlref</a>
</p>
<h2 id="++X">++X</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Auto-increment-and-Auto-decrement"><em>Auto-increment and Auto-decrement</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the prefix auto-increment operator. It is roughly equivalent to <code>X = X + 1</code>, but there is a bit of extra magic to it. If you increment a variable that is numeric, or that has ever been used in a numeric context, you get a normal increment. If, however, the variable has been used in only string contexts since it was set, and has a value that is not the empty string and matches the pattern <code>/^[a-zA-Z]*[0-9]*\z/</code>, the increment is done as a string, preserving each character within its range, with carry:
</p>
<pre>
print ++($foo = &quot;99&quot;); # prints &quot;100&quot;
print ++($foo = &quot;a0&quot;); # prints &quot;a1&quot;
print ++($foo = &quot;Az&quot;); # prints &quot;Ba&quot;
print ++($foo = &quot;zz&quot;); # prints &quot;aaa&quot;
</pre>
<p>
<code>undef</code> is always treated as numeric, and in particular is changed to <code>0</code> before incrementing (so that a post-increment of an undef value will return <code>0</code> rather than <code>undef</code>).
</p>
<p>
The incrementing occurs before the use of the value.
</p>
<h3>Example</h3>
<pre>
my $x = 4;
my $y = ++$x; #$x and $y are now 5
my $s = &quot;a&quot;;
my $t = ++$s; #$s and $t are now &quot;b&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#X++">X++</a>
</p>
<h2 id="X++">X++</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Auto-increment-and-Auto-decrement"><em>Auto-increment and Auto-decrement</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the postfix auto-increment operator. It behaves the same way as the prefix auto-increment operator <code>++X</code>, including the magic, but the value is taken before the incrementing is done. So, the after the following code <code>$x</code> will be <code>5</code> and <code>$y</code> will be 4. Whereas with the prefix auto-increment operator, both values would be <code>5</code>.
</p>
<h3>Example</h3>
<pre>
my $x = 4;
my $y = $x++; #$x is now 5 and $y is now 4
my $s = &quot;a&quot;;
my $t = $s++; #$s is now &quot;b&quot; and $t is now &quot;a&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#++X">++X</a>
</p>
<h2 id="--X">--X</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Auto-increment-and-Auto-decrement"><em>Auto-increment and Auto-decrement</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the prefix auto-decrement operator. It is equivalent to <code>X = X - 1</code>. The value returned is reflects the decrementing, so after the following code runs, <code>$x</code> and <code>$y</code> will be <code>4</code>.
</p>
<p>
X will be converted to a number before decrementing, and if it cannot be converted it will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
my $x = 5;
my $y = --$x; #$x and $y are now 4
my $s = &quot;foo&quot;;
my $t = --$s; #$s and $t are now -1
</pre>
<h3>See also</h3>
<p>
<a href="#X--">X--</a>
</p>
<h2 id="X--">X--</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Auto-increment-and-Auto-decrement"><em>Auto-increment and Auto-decrement</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the postfix auto-decrement operator. It is equivalent to <code>X = X - 1</code>. The value returned is the value before decrementing, so after the following code runs, <code>$x</code> will be 4 and <code>$y</code> will be <code>5</code>.
</p>
<p>
X will be converted to a number before the operation, and if it cannot be converted it will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
my $x = 5;
my $y = $x--; #$x is now 4 and $y is now 5
my $q = &quot;200 Quatloos for the newcomer&quot;;
my $r = $q--; #$q is now 199 and $r is &quot;200 Quatloos for the newcomer&quot;
my $s = &quot;foo&quot;;
my $t = $s--; #$s is now -1 and $t is &quot;foo&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#--X">--X</a>
</p>
<h2 id="X-**-Y">X ** Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Exponentiation"><em>Exponentiation</em> in perlop</a>
</p>
<h3>Description</h3>
<p>
This is the exponentiation operator. It raises X to the Yth power. Warning: it binds more tightly than unary minus, so <code>-2**4</code> is <code>-(2**4)</code>, not <code>(-2)**4</code>.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
my $x = 2 ** 8; #$x is now 256
my $y = log(2 ** 8)/log(2); #$y is now 8;
my $s = 2 ** &quot;foo&quot;; #$s is now 1 (2 ** 0 is 1)
my $t = 2 ** &quot;4ever&quot;; #$t is now 16
</pre>
<h3>See also</h3>
<p>
<a href="#X-**=-Y">X **= Y</a> and <a href="http://perldoc.perl.org/perlfunc.html#log"><em>log</em> in perlfunc</a>
</p>
<h2 id="!X">!X</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Symbolic-Unary-Operators"><em>Symbolic Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the high-precedence logical negation operator. It performs logical negation, i.e., &quot;not&quot;. If X is a true value it returns an empty string, otherwise it returns 1. There is a low-precedence version: <code>not</code>.
</p>
<p>
It is occasionally used in pairs (<code>!!</code>) to convert any false value to <code>&quot;&quot;</code> and any true value to <code>1</code>.
</p>
<h3>Example</h3>
<pre>
my $m = !5; #$m is now the empty string (&quot;&quot;)
my $n = !0; #$n is now 1
my $o = !&quot;&quot;; #$o is now 1
my $p = !undef; #$p is now 1
my $q = !!5; #$q is now 1
my $r = !!0; #$r is now &quot;&quot;
my $s = !!&quot;&quot;; #$s is now &quot;&quot;
my $t = !!undef; #$t is now &quot;&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#not-X">not X</a>
</p>
<h2 id="~X">~X</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Symbolic-Unary-Operators"><em>Symbolic Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the bitwise negation operator (AKA <code>1</code>&#39;s complement operator). The width of the result is platform-dependent: <code>~0</code> is <code>32</code> bits wide on a <code>32</code>-bit platform, but <code>64</code> bits wide on a <code>64</code>-bit platform, so if you are expecting a certain bit width, remember to use the <code>&amp;</code> operator to mask off the excess bits.
</p>
<p>
X will be converted to a number before the operation, and if it cannot be converted it will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
my $x = ~0x00_00_00_00 #$x is now 0xFF_FF_FF_FF on 32-bit machines
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlop.html#Bitwise-String-Operators"><em>Bitwise String Operators</em> in perlop</a> and <a href="http://perldoc.perl.org/perlop.html#Integer-Arithmetic"><em>Integer Arithmetic</em> in perlop</a>
</p>
<h2 id="\X">\X</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Symbolic-Unary-Operators"><em>Symbolic Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the backslash operator (AKA the reference operator). If X is a variable, function, or a scalar literal, then it creates a reference to X. If X is a list, then it creates a list of references to the items in the list.
</p>
<h3>Example</h3>
<pre>
my $c = \1024; #$c is now a reference to the literal 1024
my $s = 5;
my $sref = \$s; #$sref is now a reference to $s
$$sref = 6; #$s is now 6
my @a = (1, 2, 3);
my $aref = \@a; #$aref is now a reference to @a
$aref-&gt;[0] = 5; #@a is now (5, 2, 3)
push @$aref, 6; #@a is now (5, 2, 3, 6)
my %h = (a =&gt; 1, b =&gt; 2, c =&gt; 3);
my $href = \%h; #$href is now a reference to %h
$href-&gt;{b} = 5; #%h is now (a =&gt; 1, b =&gt; 5, c =&gt; 3)
my @keys = keys %$href; #@keys is now (&quot;a&quot;, &quot;b&quot;, &quot;c&quot;)
sub foo {
return join &quot;|&quot;, @_;
}
my $coderef = \&amp;foo;
my $x = $coderef-&gt;(1, 2, 3); #$x is now &quot;1|2|3&quot;;
my $y = &amp;$coderef(4, 5, 6); #$y is now &quot;4|5|6&quot;;
#@refs now holds references to $s, @a, and %h
my @refs = \($s, @a, %h);
</pre>
<h3>See also</h3>
<p>
<a href="#X->[Y]">X->[Y]</a>, <a href="#X->{Y}">X->{Y}</a>, <a href="http://perldoc.perl.org/X->(Y).html#">X->(Y)</a>, <a href="http://perldoc.perl.org/perlreftut.html#">perlreftut</a>, and <a href="http://perldoc.perl.org/perlref.html#">perlref</a>
</p>
<h2 id="+X">+X</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Symbolic-Unary-Operators"><em>Symbolic Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the unary plus operator. It has no effect whatsoever, even on strings. It is useful syntactically for separating a function name from a parenthesized expression that would otherwise be interpreted as the complete list of function arguments.
</p>
<h3>Example</h3>
<pre>
print (split &quot;,&quot;, &quot;a,b,c,d&quot;)[2], &quot;\n&quot;; #syntax error
print +(split &quot;,&quot;, &quot;a,b,c,d&quot;)[2], &quot;\n&quot;; #prints &quot;c\n&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#-X">-X</a>
</p>
<h2 id="-X">-X</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Symbolic-Unary-Operators"><em>Symbolic Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
The unary minus operator performs arithmetic negation if X is numeric.
</p>
<p>
If X is a bareword it returns a string consisting of <code>-</code> and the bareword.
</p>
<p>
If X is a string that starts with a character that matches /[_a-zA-Z]/ it returns a string consisting of <code>-</code> followed by the original string.
</p>
<p>
If X begins with <code>-</code> or <code>+</code> then the first character is converted to the opposite sign.
</p>
<p>
In all other cases, X will be converted to a number before the operation, and if it cannot be converted it will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
my $x = 10;
$x = -$x; #$x is now -10
$x = -$x; #$x is now 10 again
my $y = -option; #$y is now &quot;-option&quot;
my $z = -&quot;foo&quot;: #$z is now &quot;-foo&quot;
$z = -$z; #$z is now &quot;+foo&quot;
$z = -$z; #$z is now &quot;-foo&quot;
$z = -&quot;*foo&quot; #$z is now -0
$x = &quot;\x{e9}&quot;; #$x is now e acute
$x = -$x; #$x is now -0 because e acute is not in [_a-zA-Z]
</pre>
<h3>See also</h3>
<p>
<a href="#+X">+X</a>
</p>
<h2 id="X-=~-Y">X =~ Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Binding-Operators"><em>Binding Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the binding operator. It applies a regex match (<code>m//</code>), substitution (<code>s///</code>), or transliteration (<code>tr///</code> or <code>y///</code>) Y against a string X. When used in scalar context, the return value generally indicates the success of the operation. Behavior in list context depends on the particular operator. See <a href="http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators"><em>Regexp Quote-Like Operators</em> in perlop</a> for details and <a href="http://perldoc.perl.org/perlretut.html#">perlretut</a> for examples using these operators.
</p>
<p>
If Y is an expression rather than a search pattern, substitution, or transliteration, it is interpreted as a search pattern at run time. Note that this means that its contents will be interpolated twice, so
</p>
<pre>
&quot;\\&quot; =~ &quot;\\&quot;;
</pre>
<p>
is not ok, as the regex engine will end up trying to compile the pattern <code>\</code>, which it will consider a syntax error.
</p>
<h3>Example</h3>
<pre>
my $x = &quot;foo bar baz&quot;;
#prints &quot;matched\n&quot;
if ($x =~ /foo/) {
print &quot;matched\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlop.html#">perlop</a>, <a href="http://perldoc.perl.org/perlretut.html#">perlretut</a>, and <a href="http://perldoc.perl.org/prelre.html#">prelre</a>
</p>
<h2 id="X-!~-Y">X !~ Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Binding-Operators"><em>Binding Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the negative binding operator. It behaves like the <code>=~</code> operator, but the return is logically negated.
</p>
<h3>Example</h3>
<pre>
#prints &quot;matched\n&quot;
if (&quot;foo bar baz&quot; !~ /foo/) {
print &quot;didn&#39;t match\n&quot;;
} else {
print &quot;matched\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X-=~-Y">X =~ Y</a>
</p>
<h2 id="X-*-Y">X * Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Multiplicative-Operators"><em>Multiplicative Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the multiplication operator. It returns X multiplied by Y.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
my $x = 2 * 21; #$x is now 42
my $y = 2 * &quot;five&quot;; #$y is now 0 (2 * 0)
my $z = 2 * &quot;80s&quot;; #$z is now 160
</pre>
<h3>See also</h3>
<p>
<a href="#X-*=-Y">X *= Y</a>
</p>
<h2 id="X-/-Y">X / Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Multiplicative-Operators"><em>Multiplicative Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the division operator. It divides X by Y.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<p>
Warning: If Y is 0 or evaluates to 0 the program will die with a message like <code>Illegal division by zero</code>.
</p>
<h3>Example</h3>
<pre>
my $x = 84/2; #$x is now 42
my $y = 84/&quot;2&quot;; #$y is now 42
my $z = &quot;five&quot;/2 #$z is now 0 (0/2)
</pre>
<h3>See Also</h3>
<p>
<a href="#X-/=-Y">X /= Y</a>
</p>
<h2 id="X-%-Y">X % Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Multiplicative-Operators"><em>Multiplicative Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the modulo operator. It computes the remainder of X divided by Y. The remainder is determined differently depending on the whether the numbers are integers or floating point and whether they are positive or negative.
</p>
<p>
Given integer operands X and Y: If Y is positive, then &quot;X % Y&quot; is X minus the largest multiple of Y less than or equal to X. If Y is negative, then &quot;X % Y&quot; is X minus the smallest multiple of Y that is not less than X (i.e. the result will be less than or equal to zero). To illustrate this, here are the results of modding <code>-9</code> through <code>9</code> with <code>4</code>:
</p>
<pre>
when X is -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9
result is 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1
</pre>
<p>
And here is <code>-9</code> through <code>9</code> modded with <code>-4</code>:
</p>
<pre>
when X is -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9
result is -1 0 -3 -2 -1 0 -3 -2 -1 0 -3 -2 -1 0 -3 -2 -1 0 -3
</pre>
<p>
From this we can see a positive Y constrains X to a range from <code>0</code> to <code>(Y - 1)</code> that wraps around and a negative Y constrains X to a range from <code>(Y + 1)</code> to <code>0</code>.
</p>
<p>
When Y is a floating point number whose absolute value is in the range of <code>0</code> to <code>(UV_MAX + 1)</code> (where UV_MAX is the maximum of the unsigned integer type) X and Y are truncated to integers. If the absolute value of Y is larger than <code>(UV_MAX + 1)</code> then the formula <code>(X - I * Y)</code> (where I is a certain integer that makes the result have the same sign as Y). For example, on 32-bit systems <code>4.5 % (2 ** 32 - 1)</code> is <code>4</code>, but <code>4.5 % 2 ** 32</code> is <code>4.5</code>.
</p>
<p>
Note: when the <a href="http://perldoc.perl.org/integer.html#">integer</a> pragma is in scope <code>%</code> gives you direct access to the modulo operator as implemented by your C compiler. This operator is not as well defined for negative operands, but it will execute faster.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<p>
Warning: If Y is 0 or evaluates to 0 the program will die with a message like <code>Illegal modulus zero</code>.
</p>
<h3>Example</h3>
<pre>
my $odd = $x % 2; #$odd is 1 when $x is odd and 0 when $x is even
my $hour = ($hour + 1) % 24; # 23 (11pm) plus 1 hour is 0 (12am).
my $x = &quot;foo&quot; % 3; #$x is now 0 (0 % 3)
my $y = &quot;5&quot; % 4; #$y is now 1
</pre>
<h3>See also</h3>
<p>
<a href="#X-/-Y">X / Y</a> and <a href="#X-%=-Y">X %= Y</a>
</p>
<h2 id="X-x-Y">X x Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Multiplicative-Operators"><em>Multiplicative Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the repetition operator. When X is a scalar value it returns a string made up of X repeated Y times. When X is a list it returns a list made up of X repeated Y times. If Y is less than 1 an empty string is returned.
</p>
<p>
Y will be converted to a number before the operation, and if it cannot be converted it will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
my $x = &quot;abc&quot; x 3; #$x is now the string &quot;abcabcabc&quot;
my @a = (&quot;abc&quot;) x 3; #@a is now (&quot;abc&quot;, &quot;abc&quot;, &quot;abc&quot;)
my $s = &quot;abcd&quot; x &quot;a&quot;; #$s is now &quot;&quot; (&quot;abcd&quot; x 0)
my $t = &quot;abcd&quot; x &quot;2&quot;; #$t is now &quot;abddabcd&quot;
</pre>
<h2 id="X-+-Y">X + Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Additive-Operators"><em>Additive Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the addition operator. It returns the result of X plus Y.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
my $x = 40 + 2; #$x is now 42
my $y = 40 + &quot;a&quot;; #$y is now 40 (40 + 0)
my $y = 40 + &quot;2&quot;; #$y is now 42
</pre>
<h3>See also</h3>
<p>
<a href="#X-+=-Y">X += Y</a>
</p>
<h2 id="X---Y">X - Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Additive-Operators"><em>Additive Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the subtraction operator. It returns the result of X minus Y.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
my $x = 100 - 58; #$x is now 42
my $y = 100 - &quot;five&quot;; #$y is now 100 (100 - 0)
my $z = 100 - &quot;58&quot;; #$z is now 42
</pre>
<h3>See also</h3>
<p>
<a href="#X--=-Y">X -= Y</a>
</p>
<h2 id="X-.-Y">X . Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Additive-Operators"><em>Additive Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the concatenation operator. It coerces its arguments to strings, then returns a new string that begins with X and ends with Y. It forces scalar context on X and Y.
</p>
<h3>Example</h3>
<pre>
my @a = (1 .. 10);
my $x = &quot;foo&quot; . &quot;bar&quot;; #$x is now &quot;foobar&quot;
my $y = &quot;the number of elements in \@a is&quot; . @a;
</pre>
<h3>See also</h3>
<p>
<a href="#X-.=-Y">X .= Y</a>
</p>
<h2 id="X-<<-Y">X << Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Shift-Operators"><em>Shift Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the left bit-shift operator. It shift bits that make up the integer X Y places to the left. If X is not an integer it will be converted into one before the operation begins.
</p>
<p>
New bits added to the right side are all <code>0</code>. Overflowing the integer type on you platform (i.e. creating a number too large to store in your platform&#39;s integer type) results in behavior that is not well defined (i.e. it is platform specific). When Y is negative the results are also not well defined. This is because the left bit-shift operator is implemented by the native C compiler&#39;s left bit-shift operator (and those operations are not defined by ISO C).
</p>
<p>
Shifting 1 bit to the left is the same as multiplying the number by 2.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
#on 32-bit machines
my $x = 0xFF_00_FF_00 &lt;&lt; 8; #$x is now not well defined
#on 64-bit machines
my $y = 0xFF_00_FF_00 &lt;&lt; 8; #$y is now 0xFF_00_FF_00_00
my $z = 6 &lt;&lt; 1; #$z is now 12
</pre>
<h3>See also</h3>
<p>
<a href="#X-<<=-Y">X <<= Y</a>
</p>
<h2 id="X->>-Y">X >> Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Shift-Operators"><em>Shift Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the right-bit shift operator. It shift bits that make up the integer X Y places to the right. If X is not an integer it will be converted into one before the operation begins. Bits shifted past the rightmost edge are lost. New bits added to the left side are all 0. Shifting to the right one bit is the same as an integer division by 2.
</p>
<p>
When Y is negative the results are not well defined (i.e. platform specific). This is because the right bit-shift operator is implemented by the native C compiler&#39;s right bit-shift operator (and that is not defined by ISO C).
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
my $x = 0x00_FF_00_FF &gt;&gt; 8; #$x is now 0x00_00_FF_00
my $y = 12 &gt;&gt; 1; #$y is now 6
</pre>
<h3>See also</h3>
<p>
<a href="#X->>=-Y">X >>= Y</a>
</p>
<h2 id="-r-FILE">-r FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the effective uid/gid readable filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file or directory exists and is readable by the effective uid/gid, <code>&quot;&quot;</code> if it exists but if it not readable, or <code>undef</code> if the file does not exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -r &quot;/etc/passwd&quot;) {
if (-r _) {
print &quot;/etc/passwd is readable\n&quot;;
} else {
print &quot;/etc/passwd is not readable\n&quot;;
}
} else {
print &quot;/etc/passwd doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlvar.html#$>"><em>$&gt;</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlvar.html#$)"><em>$)</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-w-FILE">-w FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the effective uid/gid writable filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file or directory exists and is writable by the effective uid/gid, <code>&quot;&quot;</code> if it exists but if it not writable, or <code>undef</code> if the file does not exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -w &quot;/etc/passwd&quot;) {
if (-w _) {
print &quot;/etc/passwd is writable\n&quot;;
} else {
print &quot;/etc/passwd is not writable\n&quot;;
}
} else {
print &quot;/etc/passwd doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlvar.html#$>"><em>$&gt;</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlvar.html#$)"><em>$)</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-x-FILE">-x FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the effective uid/gid executable filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file or directory exists and is executable by the effective uid/gid, <code>&quot;&quot;</code> if it exists but if it not executable, or <code>undef</code> if the file does not exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -x $0) {
if (-x _) {
print &quot;this script is executable\n&quot;;
} else {
print &quot;this script is not executable\n&quot;;
}
} else {
print &quot;this script doesn&#39;t exist on the filesystem\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlvar.html#$>"><em>$&gt;</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlvar.html#$)"><em>$)</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-o-FILE">-o FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the effective owner filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file or directory exists and is owned by the effective uid, <code>&quot;&quot;</code> if it exists but if it not owned by the effective uid, or <code>undef</code> if the file does not exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -o $0) {
if (-o _) {
print &quot;this script is owned by $&gt;\n&quot;;
} else {
print &quot;this script is not owned by $&gt;\n&quot;;
}
} else {
print &quot;this script doesn&#39;t exist on the filesystem\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlvar.html#$>"><em>$&gt;</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlvar.html#$)"><em>$)</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-R-FILE">-R FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the real uid/gid readable filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file or directory exists and is readable by the real uid/gid, <code>&quot;&quot;</code> if it exists but if it not readable, or <code>undef</code> if the file does not exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -R &quot;/etc/passwd&quot;) {
if (-R _) {
print &quot;/etc/passwd is readable\n&quot;;
} else {
print &quot;/etc/passwd is not readable\n&quot;;
}
} else {
print &quot;/etc/passwd doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlvar.html#$<"><em>$&lt;</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlvar.html#$("><em>$(</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-W-FILE">-W FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the real uid/gid writable filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file or directory exists and is writable by the real uid/gid, <code>&quot;&quot;</code> if it exists but if it not writable, or <code>undef</code> if the file does not exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -W &quot;/etc/passwd&quot;) {
if (-W _) {
print &quot;/etc/passwd is writable\n&quot;;
} else {
print &quot;/etc/passwd is not writable\n&quot;;
}
} else {
print &quot;/etc/passwd doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlvar.html#$<"><em>$&lt;</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlvar.html#$("><em>$(</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-X-FILE">-X FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the real uid/gid executable filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file or directory exists and is executable by the real uid/gid, <code>&quot;&quot;</code> if it exists but if it not executable, or <code>undef</code> if the file does not exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -X $0) {
if (-X _) {
print &quot;this script is executable\n&quot;;
} else {
print &quot;this script is not executable\n&quot;;
}
} else {
print &quot;this script doesn&#39;t exist on the filesystem\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlvar.html#$<"><em>$&lt;</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlvar.html#$("><em>$(</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-O-FILE">-O FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the real owner filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file or directory exists and is owned by the real uid, <code>&quot;&quot;</code> if it exists but if it not owned by the effective uid, or <code>undef</code> if the file does not exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -O $0) {
if (-O _) {
print &quot;this script is owned by $&gt;\n&quot;;
} else {
print &quot;this script is not owned by $&gt;\n&quot;;
}
} else {
print &quot;this script doesn&#39;t exist on the filesystem\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlvar.html#$<"><em>$&lt;</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlvar.html#$("><em>$(</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-e-FILE">-e FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the existence filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file or directory exists or <code>undef</code> if the file or directory does not exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (-e $0) {
print &quot;this script exists\n&quot;;
} else {
print &quot;this script doesn&#39;t exist on the filesystem\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-z-FILE">-z FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the empty filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file or directory exists and has zero size, <code>&quot;&quot;</code> if the file or directory exists, but has zero size, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -z &quot;/tmp/somefile&quot;) {
if (-z _) {
print &quot;somefile is empty\n&quot;;
} else {
print &quot;somefile has data in it\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-s-FILE">-s FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the size filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns the size of the file in bytes if the file or directory exists or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -s &quot;/tmp/somefile&quot;) {
print &quot;somefile is &quot;, -s _, &quot; byte(s) long\n&quot;;
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-f-FILE">-f FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the regular file filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file exists and is a regular file, <code>&quot;&quot;</code> if the file or directory exists, but isn&#39;t a regular file, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -f &quot;/tmp/somefile&quot;) {
if (-f _) {
print &quot;somefile is a regular file\n&quot;;
} else {
print &quot;somefile is not a regular file\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-d-FILE">-d FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the directory filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the directory exists , <code>&quot;&quot;</code> if the file exists, but isn&#39;t a directory file, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -d &quot;/tmp/somefile&quot;) {
if (-d _) {
print &quot;somefile is a directory\n&quot;;
} else {
print &quot;somefile is not a directory\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-l-FILE">-l FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the symbolic link filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file or directory exists and is a symbolic link, <code>&quot;&quot;</code> if the file or directory exists, but isn&#39;t a symbolic link, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -l &quot;/tmp/somefile&quot;) {
if (-l _) {
print &quot;somefile is a symbolic link\n&quot;;
} else {
print &quot;somefile is not a symbolic link\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-p-FILE">-p FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the pipe filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file exists and is a pipe, <code>&quot;&quot;</code> if the file or directory exists, but isn&#39;t a pipe, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -p &quot;/tmp/somefile&quot;) {
if (-p _) {
print &quot;somefile is a pipe\n&quot;;
} else {
print &quot;somefile is not a pipe\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
if (-p STDOUT) {
print &quot;we are piping to another program\n&quot;;
} else {
print &quot;we are not piping to another program\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-S-FILE">-S FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the socket filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file exists and is a socket, <code>&quot;&quot;</code> if the file or directory exists, but isn&#39;t a socket, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -S &quot;/tmp/somefile&quot;) {
if (-S _) {
print &quot;somefile is a socket\n&quot;;
} else {
print &quot;somefile is not a socket\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-b-FILE">-b FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the block special filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file exists and is a block special file, <code>&quot;&quot;</code> if the file or directory exists, but isn&#39;t a block special file, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -b &quot;/tmp/somefile&quot;) {
if (-b _) {
print &quot;somefile is a block special file\n&quot;;
} else {
print &quot;somefile is not a block special file\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-c-FILE">-c FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the character special filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file exists and is a character special file, <code>&quot;&quot;</code> if the file or directory exists, but isn&#39;t a character special file, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -c &quot;/tmp/somefile&quot;) {
if (-c _) {
print &quot;somefile is a character special file\n&quot;;
} else {
print &quot;somefile is not a character special file\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-t-FILE">-t FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the socket filetest operator. FILE must be a filehandle or an expression that returns one. It returns <code>1</code> if the filehandle is opened to a tty or <code>undef</code> if it is not.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<h3>Example</h3>
<pre>
if (-t STDOUT) {
print &quot;output is going to a console\n&quot;;
} else {
print &quot;output is being redirected\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-u-FILE">-u FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the setuid filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file exists and has its setuid set, <code>&quot;&quot;</code> if the file or directory exists, but its setuid isn&#39;t set, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -u &quot;/tmp/somefile&quot;) {
if (-u _) {
print &quot;somefile has setuid set\n&quot;;
} else {
print &quot;somefile dosn&#39;t have setuid set\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-g-FILE">-g FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the setgid filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file exists and has its setgid set, <code>&quot;&quot;</code> if the file or directory exists, but its setgid isn&#39;t set, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -u &quot;/tmp/somefile&quot;) {
if (-u _) {
print &quot;somefile has setgid set\n&quot;;
} else {
print &quot;somefile dosn&#39;t have setgid set\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-k-FILE">-k FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the sticky bit filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file exists and has its sticky bit set, <code>&quot;&quot;</code> if the file or directory exists, but its sticky bit isn&#39;t set, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -k &quot;/tmp/somefile&quot;) {
if (-k _) {
print &quot;somefile has sticky bit set\n&quot;;
} else {
print &quot;somefile dosn&#39;t have sticky bit set\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-T-FILE">-T FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the ASCII text filetest operator. FILE must be a filename, filehandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file exists and appears to be a text file, <code>&quot;&quot;</code> if the file or directory exists, but doesn&#39;t appear to be a text file, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If X is a filename, it guesses the type of the file by reading the first block from the file. If the first block doesn&#39;t contain any nul characters (i.e. <code>\0</code>) and it contains fewer than thirty percent control characters or characters that have their high bits set, then it is considered an ASCII text file.
</p>
<p>
If X is a filehandle it guess the type the same way, but uses the current IO buffer instead of the first block.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -T &quot;/tmp/somefile&quot;) {
if (-T _) {
print &quot;somefile looks like a text file\n&quot;;
} else {
print &quot;somefile lokks like a data file\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#-B">-B</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-B-FILE">-B FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the binary filetest operator. FILE must be a filename, filehandle, or an expression that returns one of the preceding values. It returns <code>1</code> if the file exists and appears to be a binary file, <code>&quot;&quot;</code> if the file or directory exists, but doesn&#39;t appear to be a binary file, or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If X is a filename, it guesses the type of the file by reading the first block from the file. If the first block contains any nul characters (i.e. <code>\0</code>) or it contains more than thirty percent control characters or characters that have their high bits set, then it is considered a binary file.
</p>
<p>
If X is a filehandle it guess the type the same way, but uses the current IO buffer instead of the first block.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<h3>Example</h3>
<pre>
if (defined -B &quot;/tmp/somefile&quot;) {
if (-B _) {
print &quot;somefile lokks like a data file\n&quot;;
} else {
print &quot;somefile looks like a text file\n&quot;;
}
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#-T">-T</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a> and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-M-FILE">-M FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the mtime filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns the script start time minus file modification time, in days, if the file or directory exists or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<p>
The script start time is stored in <code>$^T</code>, so modifying this variable will have an affect on the results of calling <code>-M</code> on a file.
</p>
<h3>Example</h3>
<pre>
if (-M &quot;somefile&quot;) {
print &quot;it has been &quot;, -M _, &quot; days since somefile was modified\n&quot;;
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlvar.html#$^T"><em>$^T</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a>, and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-A-FILE">-A FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the atime filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns the script start time minus file access time, in days, if the file or directory exists or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<p>
The script start time is stored in <code>$^T</code>, so modifying this variable will have an affect on the results of calling <code>-A</code> on a file.
</p>
<p>
Warning: many filesystems now turn off atime updating.
</p>
<h3>Example</h3>
<pre>
if (-A &quot;somefile&quot;) {
print &quot;it has been &quot;, -A _, &quot; days since somefile was accessed\n&quot;;
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlvar.html#$^T"><em>$^T</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a>, and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="-C-FILE">-C FILE</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Named-Unary-Operators"><em>Named Unary Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the ctime filetest operator. FILE must be a filename, filehandle, dirhandle, or an expression that returns one of the preceding values. It returns the script start time minus the ctime of the file, in days, if the file or directory exists or <code>undef</code> if the file or directory doesn&#39;t exist.
</p>
<p>
If given no arguments, it will operate on <code>$_</code>.
</p>
<p>
If given the <code>_</code> special filehandle as an argument, it will use cached information from the previous call to <code>stat</code> or a filetest operator.
</p>
<p>
The script start time is stored in <code>$^T</code>, so modifying this variable will have an affect on the results of calling <code>-A</code> on a file.
</p>
<p>
Warning, different filesystems have different ideas about what the ctime is. In Unix, the ctime is the inode change time. The ctime is updated when a change occurs to the file&#39;s inode (permissions change, ownership change, etc.).
</p>
<h3>Example</h3>
<pre>
if (-A &quot;somefile&quot;) {
print &quot;it has been &quot;, -A _, &quot; days since somefile was accessed\n&quot;;
} else {
print &quot;somefile doesn&#39;t exist\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlvar.html#$^T"><em>$^T</em> in perlvar</a>, <a href="http://perldoc.perl.org/perlfunc.html#-X"><em>-X</em> in perlfunc</a>, and <a href="http://perldoc.perl.org/perlfunc.html#stat"><em>stat</em> in perlfunc</a>
</p>
<h2 id="X-<-Y">X < Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Relational-Operators"><em>Relational Operators</em> in perlop</a>
</p>
<h3>Description</h3>
<p>
This is the numeric less than operator. It returns a true value if X is numerically less than Y or a false value if X is greater than or equal to Y.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
if (4 &lt; 5) {
print &quot;this is true unless Perl is broken\n&quot;;
}
if (5 &lt; 4) {
print &quot;this should never be true\n&quot;;
} else {
print &quot;it should always be false\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X-<=-Y">X <= Y</a>, <a href="#X-lt-Y">X lt Y</a>, and <a href="#X-le-Y">X le Y</a>
</p>
<h2 id="X->-Y">X > Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Relational-Operators"><em>Relational Operators</em> in perlop</a>
</p>
<h3>Description</h3>
<p>
This is the numeric greater than operator. It returns a true value if X is numerically greater than Y or a false value if X is less than or equal to Y.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
if (5 &gt; 4) {
print &quot;this is true unless Perl is broken\n&quot;;
}
if (4 &gt; 5) {
print &quot;this should never be true\n&quot;;
} else {
print &quot;it should always be false\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X->=-Y">X >= Y</a> <a href="#X-gt-Y">X gt Y</a>, and <a href="#X-ge-Y">X ge Y</a>
</p>
<h2 id="X-<=-Y">X <= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Relational-Operators"><em>Relational Operators</em> in perlop</a>
</p>
<h3>Description</h3>
<p>
This is the numeric less than or equal to operator. It returns a true value if X is numerically less than or equal to Y or a false value if X is greater than to Y.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
if (4 &lt;= 4) {
print &quot;this is true unless Perl is broken\n&quot;;
}
if (5 &lt;= 4) {
print &quot;this should never be true\n&quot;;
} else {
print &quot;it should always be false\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X-<-Y">X < Y</a>, <a href="#X-lt-Y">X lt Y</a>, and <a href="#X-le-Y">X le Y</a>
</p>
<h2 id="X->=-Y">X >= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Relational-Operators"><em>Relational Operators</em> in perlop</a>
</p>
<h3>Description</h3>
<p>
This is the numeric less than or equal to operator. It returns a true value if X is numerically less than or equal to Y or a false value if X is greater than to Y.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
if (4 &gt;= 4) {
print &quot;this is true unless Perl is broken\n&quot;;
}
if (4 &gt;= 5) {
print &quot;this should never be true\n&quot;;
} else {
print &quot;it should always be false\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X->-Y">X > Y</a>, <a href="#X-gt-Y">X gt Y</a>, and <a href="#X-ge-Y">X ge Y</a>
</p>
<h2 id="X-lt-Y">X lt Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Relational-Operators"><em>Relational Operators</em> in perlop</a>
</p>
<h3>Description</h3>
<p>
This is the lexical less than operator (also known as the string less than operator or the stringwise less than operator). It returns true if X is less than Y and false if X is greater than or equal to Y. The order of various characters is locale dependent. The default order is determined by the Unicode ordinal value (since Unicode contains the ASCII set as its first <code>127</code> characters, this order is the same as the ASCII order).
</p>
<h3>Example</h3>
<pre>
if (&quot;a&quot; lt &quot;b&quot;) {
print &quot;this is true unless the locale is really weird\n&quot;;
}
if (&quot;z&quot; lt &quot;a&quot;) {
print &quot;this should never be true (unless the local is weird)\n&quot;;
} else {
print &quot;it should always be false (unless the local is weird)\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X-<-Y">X < Y</a>, <a href="#X-<=-Y">X <= Y</a>, and <a href="#X-le-Y">X le Y</a> <a href="#X-cmp-Y">X cmp Y</a>
</p>
<h2 id="X-gt-Y">X gt Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Relational-Operators"><em>Relational Operators</em> in perlop</a>
</p>
<h3>Description</h3>
<p>
This is the lexical greater than operator (also known as the string greater than operator or the stringwise greater than operator). It returns true if X is greater than Y and false if X is less than or equal to Y. The order of various characters is locale dependent. The default order is determined by the Unicode ordinal value (since Unicode contains the ASCII set as its first <code>127</code> characters, this order is the same as the ASCII order).
</p>
<h3>Example</h3>
<pre>
if (&quot;b&quot; gt &quot;a&quot;) {
print &quot;this is true unless the locale is really weird\n&quot;;
}
if (&quot;a&quot; gt &quot;z&quot;) {
print &quot;this should never be true (unless the local is weird)\n&quot;;
} else {
print &quot;it should always be false (unless the local is weird)\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X->-Y">X > Y</a>, <a href="#X-">X </a>= Y&gt;, and <a href="#X-ge-Y">X ge Y</a>
</p>
<h2 id="X-le-Y">X le Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Relational-Operators"><em>Relational Operators</em> in perlop</a>
</p>
<h3>Description</h3>
<p>
This is the lexical less than or equal to operator (also known as the string less than or equal to operator or the stringwise less than or equal to operator). It returns true if X is less than or equal to Y and false if X is greater than Y. The order of various characters is locale dependent. The default order is determined by the Unicode ordinal value (since Unicode contains the ASCII set as its first <code>127</code> characters, this order is the same as the ASCII order).
</p>
<h3>Example</h3>
<pre>
if (&quot;a&quot; le &quot;a&quot;) {
print &quot;this is true unless Perl is broken\n&quot;;
}
if (&quot;z&quot; le &quot;a&quot;) {
print &quot;this should never be true (unless the local is weird)\n&quot;;
} else {
print &quot;it should always be false (unless the local is weird)\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X-<-Y">X < Y</a>, <a href="#X-<=-Y">X <= Y</a>, and <a href="#X-lt-Y">X lt Y</a>
</p>
<h2 id="X-ge-Y">X ge Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Relational-Operators"><em>Relational Operators</em> in perlop</a>
</p>
<h3>Description</h3>
<p>
This is the lexical greater than or equal to operator (also known as the string greater than or equal to operator or the stringwise greater than or equal to operator). It returns true if X is greater than Y and false if X is less than or equal to Y. The order of various characters is locale dependent. The default order is determined by the Unicode ordinal value (since Unicode contains the ASCII set as its first <code>127</code> characters, this order is the same as the ASCII order).
</p>
<h3>Example</h3>
<pre>
if (&quot;a&quot; ge &quot;a&quot;) {
print &quot;this is true unless Perl is broken\n&quot;;
}
if (&quot;a&quot; ge &quot;z&quot;) {
print &quot;this should never be true (unless the local is weird)\n&quot;;
} else {
print &quot;it should always be false (unless the local is weird)\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X->-Y">X > Y</a>, <a href="#X->=-Y">X >= Y</a>, <a href="#X-gt-Y">X gt Y</a>, and <a href="#X-cmp-Y">X cmp Y</a>
</p>
<h2 id="X-==-Y">X == Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Equality-Operators"><em>Equality Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the numeric equality operator. It returns true if X and Y evaluate as the same number.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<p>
Important note: the numeric equality operator should not be used with floating point numbers as the error introduced by rounding may cause the number to not be exactly what you are comparing against. Always use the less than and greater than operators with a small delta:
</p>
<pre>
my $x = 0;
for (1 .. 10) {
$x += .1;
}
if ($x == 1) {
print &quot;$x is one\n&quot;;
} else {
print &quot;oops, darn floating point numbers\n&quot;;
}
my $delta = 1e-15; #0.000000000000001
if (
$x &lt; 1 + $delta and
$x &gt; 1 - $delta
) {
print &quot;this time it worked\n&quot;;
}
</pre>
<h3>Example</h3>
<pre>
if (5 == 5) {
print &quot;this will be true unless Perl is broken\n&quot;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X-!=-Y">X != Y</a>, <a href="#X-eq-Y">X eq Y</a>, and <a href="#X-ne-Y">X ne Y</a>
</p>
<h2 id="X-!=-Y">X != Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Equality-Operators"><em>Equality Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the numeric not equals operator. It returns true if X does not evaluate to the same numeric value as Y.
</p>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<p>
Important note: the numeric equality operator should not be used with floating point numbers as the error introduced by rounding may cause the number to not be exactly what you are comparing against. Always use the less than and greater than operators with a small delta:
</p>
<pre>
my $x = 0;
for (1 .. 10) {
$x += .1;
}
if ($x != 1) {
print &quot;oops, darn floating point numbers\n&quot;;
}
my $delta = 1e-15; #0.000000000000001
if (
$x &gt; 1 + $delta and
$x &lt; 1 - $delta
) {
print &quot;wow, your floating point representation is really good\n&quot;;
} else {
print &quot;this time it worked\n&quot;;
}
</pre>
<h3>Example</h3>
<pre>
if (5 != 4) {
print &quot;this will be true unless Perl is broken\n&quot;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X-==-Y">X == Y</a>, <a href="#X-eq-Y">X eq Y</a>, and <a href="#X-ne-Y">X ne Y</a>
</p>
<h2 id="X-<=>-Y">X <=> Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Equality-Operators"><em>Equality Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the numeric comparison operator. It returns less than <code>0</code> if X is numerically less than Y, <code>0</code> is if X and Y are the same numerically, or more than <code>0</code> if X is numerically greater than Y. It is most often seen combined with the <code>sort</code> function:
</p>
<pre>
my @sorted = sort { $a &lt;=&gt; $b } @unsorted;
</pre>
<p>
Both X and Y will be converted to numbers before the operation; if they cannot be converted they will turned into <code>0</code> (and a warning is thrown if <a href="http://perldoc.perl.org/warnings.html#">warnings</a> are turned on).
</p>
<h3>Example</h3>
<pre>
my $x = 4 &lt;=&gt; 5; #x is now negative
my $y = 5 &lt;=&gt; 5; #y is now 0
my $z = 6 &lt;=&gt; 5; #z is now positive
</pre>
<h3>See also</h3>
<p>
<a href="#X-cmp-Y">X cmp Y</a>
</p>
<h2 id="X-eq-Y">X eq Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Equality-Operators"><em>Equality Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the lexical equality operator (aka the string equality operator or the stringwise equality operator). It returns true if X and Y evaluate as the same string.
</p>
<h3>Example</h3>
<pre>
if (&quot;foo&quot; eq &quot;foo&quot;) {
print &quot;this is true, unless Perl is broken\n&quot;;
}
if (&quot;foo&quot; eq &quot;bar&quot;) {
print &quot;this is should always be false, unless Perl is broken\n&quot;;
} else {
print &quot;this is false, unless Perl is broken\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X-==-Y">X == Y</a>, <a href="#X-!=-Y">X != Y</a>, and <a href="#X-ne-Y">X ne Y</a>
</p>
<h2 id="X-ne-Y">X ne Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Equality-Operators"><em>Equality Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the lexical not equals operator. (aka the string not equals operator or the stringwise not equals operator). It returns false if X and Y evaluate as the same string.
</p>
<h3>Example</h3>
<pre>
if (&quot;foo&quot; ne &quot;bar&quot;) {
print &quot;this is true, unless Perl is broken\n&quot;;
}
if (&quot;foo&quot; ne &quot;foo&quot;) {
print &quot;this is should always be false, unless Perl is broken\n&quot;;
} else {
print &quot;this is false, unless Perl is broken\n&quot;;
}
</pre>
<h3>See also</h3>
<p>
<a href="#X-==-Y">X == Y</a>, <a href="#X-!=-Y">X != Y</a>, and <a href="#X-eq-Y">X eq Y</a>
</p>
<h2 id="X-cmp-Y">X cmp Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Equality-Operators"><em>Equality Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the lexical comparison operator (also known as the string comparison operator or the stringwise comparison operator). It returns a negative value if X is lexically less than Y, <code>0</code> is X and Y are lexically the same, or a positive value if X is lexically larger than Y. This comparison is affected by the current locale and the default order is determined by the Unicode ordinal value (since Unicode contains the ASCII set as its first <code>127</code> characters, this order is the same as the ASCII order). It is most commonly seen used with the <code>sort</code> function:
</p>
<pre>
my @sorted = sort { $a cmp $b } @unsorted;
</pre>
<h3>Example</h3>
<pre>
my $x = &quot;a&quot; &lt;=&gt; &quot;b&quot;; #$x is now negative
my $y = &quot;b&quot; &lt;=&gt; &quot;b&quot;; #$x is now 0
my $z = &quot;c&quot; &lt;=&gt; &quot;b&quot;; #$x is now positive
</pre>
<h3>See also</h3>
<p>
<a href="#X-<=>-Y">X <=> Y</a>
</p>
<h2 id="X-~~-Y">X ~~ Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Equality-Operators"><em>Equality Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the smartmatch operator. In 5.10 and 5.10.1 it has different behavior. See <a href="http://perldoc.perl.org/perlsyn.html#Smart-matching-in-detail"><em>Smart matching in detail</em> in perlsyn</a> for more detail.
</p>
<p>
Prior to 5.10, it was sometimes used to mean <code>~(~X)</code> which has the affect of forcing scalar context on X. You should use the <code>scalar</code> function for that purpose instead.
</p>
<h3>Example</h3>
<p>
See <a href="http://perldoc.perl.org/perlsyn.html#Smart-matching-in-detail"><em>Smart matching in detail</em> in perlsyn</a> for examples.
</p>
<h3>See also</h3>
<p>
<a href="#~~X">~~X</a>, <a href="http://perldoc.perl.org/perlsyn.html#Smart-matching-in-detail"><em>Smart matching in detail</em> in perlsyn</a>, and <a href="http://perldoc.perl.org/perlfunc.html#scalar"><em>scalar</em> in perlfunc</a>
</p>
<h2 id="X-&-Y">X & Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Bitwise-And"><em>Bitwise And</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the bitwise and operator. It ands together the individual bits of X and Y. The truth table for and is:
</p>
<pre>
X Y R
-----+---
0 0 | 0
0 1 | 0
1 0 | 0
1 1 | 1
</pre>
<p>
That is, it sets the result bit to 1 if both the X and Y bits are 1, otherwise it sets the result bit to 0. This operation is done for every bit in X and Y.
</p>
<p>
If both operands are strings, they are considered character by character. The result is determined by anding the ordinal value of the characters, so <code>&quot;a&quot; &amp; &quot;b&quot;</code> is equivalent to <code>chr(ord(&quot;a&quot;) &amp; ord(&quot;b&quot;))</code>. If X and Y are different sizes, then the longer string is truncated to the length of the shorter string.
</p>
<h3>Example</h3>
<pre>
#0x4545 is 0b0000_0100_0000_0101_0000_0100_0000_0101
#0x00FF is 0b0000_0000_0000_0000_1111_1111_1111_1111
#0x4545 &amp; 0x00FF is 0b0000_0000_0000_0000_0000_0100_0000_0101 or 0x0045
my $z = 0x4545 &amp; 0x00FF; #$z is now 0x0045
#In ASCII (and UTF-8)
#&quot;a&quot; is 0b0110_0001
#&quot;b&quot; is 0b0110_0010
#&quot;a&quot; &amp; &quot;b&quot; is 0b0110_0000 or &quot;`&quot;
my $x = &quot;a&quot; &amp; &quot;b&quot;; #$x is now &quot;`&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#X-and-Y">X and Y</a>, <a href="#X-&&-Y">X && Y</a>, <a href="http://perldoc.perl.org/perlop.html#Integer-Arithmetic"><em>Integer Arithmetic</em> in perlop</a> and <a href="http://perldoc.perl.org/perlop.html#Bitwise-String-Operators"><em>Bitwise String Operators</em> in perlop</a>.
</p>
<h2 id="X-|-Y">X | Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Bitwise-Or-and-Exclusive-Or"><em>Bitwise Or and Exclusive Or</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the bitwise or operator. It ors together the individual bits of X and Y. The truth table for or is:
</p>
<pre>
X Y R
-----+---
0 0 | 0
0 1 | 1
1 0 | 1
1 1 | 1
</pre>
<p>
That is, it sets the result bit to 0 if both the X and Y bits are 0, otherwise it sets the result bit to 1. This operation is done for every bit in X and Y.
</p>
<p>
If both operands are strings, they are considered character by character. The result is determined by oring the ordinal value of the characters, so <code>&quot;a&quot; | &quot;b&quot;</code> is equivalent to <code>chr(ord(&quot;a&quot;) | ord(&quot;b&quot;))</code>. If X and Y are different sizes, then the shorter item is treated as if it had additional bits that are set to 0.
</p>
<h3>Example</h3>
<pre>
#0x4545 is 0b0000_0100_0000_0101_0000_0100_0000_0101
#0x00FF is 0b0000_0000_0000_0000_1111_1111_1111_1111
#0x4545 | 0x00FF is 0b0000_0100_0000_0101_1111_1111_1111_1111 or 0x45FF
my $y = 0x4545 | 0x00FF; #$y is now 0x45FF
#In ASCII (and UTF-8)
#&quot;a&quot; is 0b0110_0001
#&quot;b&quot; is 0b0110_0010
#&quot;a&quot; | &quot;b&quot; is 0b0110_0011 or &quot;c&quot;
my $x = &quot;a&quot; | &quot;b&quot;; #$x is now &quot;c&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#X-or-Y">X or Y</a>, <a href="#X-xor-Y">X xor Y</a>, <a href="#X-||-Y">X || Y</a>, <a href="#X-//-Y">X // Y</a>, <a href="#X-^-Y">X ^ Y</a>, <a href="http://perldoc.perl.org/perlop.html#Integer-Arithmetic"><em>Integer Arithmetic</em> in perlop</a>, and <a href="http://perldoc.perl.org/perlop.html#Bitwise-String-Operators"><em>Bitwise String Operators</em> in perlop</a>.
</p>
<h2 id="X-^-Y">X ^ Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Bitwise-Or-and-Exclusive-Or"><em>Bitwise Or and Exclusive Or</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the bitwise exclusive-or operator. It exclusive-ors together the individual bits of X and Y. The truth table for exclusive-or is:
</p>
<pre>
X Y R
-----+---
0 0 | 0
0 1 | 1
1 0 | 1
1 1 | 0
</pre>
<p>
That is, it sets the result bit to 1 if X or Y is set, or 0 if both or neither is set. This operation is done for every bit in X and Y.
</p>
<p>
If both operands are strings, they are considered character by character. The result is determined by exclusive-oring the ordinal value of the characters, so <code>&quot;a&quot; ^ &quot;b&quot;</code> is equivalent to <code>chr(ord(&quot;a&quot;) ^ ord(&quot;b&quot;))</code>. If X and Y are different sizes, then the shorter item is treated as if it had additional bits that are set to 0.
</p>
<h3>Example</h3>
<pre>
#0x4545 is 0b0000_0100_0000_0101_0000_0100_0000_0101
#0x00FF is 0b0000_0000_0000_0000_1111_1111_1111_1111
#0x4545 ^ 0x00FF is 0b0000_0100_0000_0101_1111_1111_1111_1010 or 0x45BA
my $y = 0x4545 ^ 0x00FF; #$y is now 0x45BA
#In ASCII (and UTF-8)
#&quot;a&quot; is 0b0110_0001
#&quot;b&quot; is 0b0110_0010
#&quot;a&quot; ^ &quot;b&quot; is 0b0000_0011 or &quot;\x{03}&quot;
my $x = &quot;a&quot; ^ &quot;b&quot;; #$x is now &quot;\x{03}&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#X-or-Y">X or Y</a>, <a href="#X-xor-Y">X xor Y</a>, <a href="#X-||-Y">X || Y</a>, <a href="#X-//-Y">X // Y</a>, <a href="#X-|-Y">X | Y</a>, <a href="http://perldoc.perl.org/perlop.html#Integer-Arithmetic"><em>Integer Arithmetic</em> in perlop</a> and <a href="http://perldoc.perl.org/perlop.html#Bitwise-String-Operators"><em>Bitwise String Operators</em> in perlop</a>.
</p>
<h2 id="X-&&-Y">X && Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#C-style-Logical-And"><em>C-style Logical And</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the high-precedence logical and operator. It returns X if X evaluates to false, otherwise it returns Y.
</p>
<p>
It binds more tightly than the low-precedence logical and operator:
</p>
<pre>
my $x = 5 &amp;&amp; 4; # is equivalent to my $x = (5 &amp;&amp; 4);
</pre>
<p>
whereas:
</p>
<pre>
my $y = 5 and 4; # is equivalent to (my $x = 5) and 4;
</pre>
<p>
It is most commonly used in conditional statements such as <code>if</code>, <code>unless</code>, <code>while</code>.
</p>
<h3>Example</h3>
<pre>
my $w = &quot;&quot;;
my $x = 0;
my $y = 1;
my $z = &quot;foo&quot;;
print $w &amp;&amp; $y, &quot;\n&quot;; #prints &quot;\n&quot;
print $x &amp;&amp; $y, &quot;\n&quot;; #prints &quot;0\n&quot;
print $y &amp;&amp; $z, &quot;\n&quot;; #prints &quot;foo\n&quot;
print $z &amp;&amp; $y, &quot;\n&quot;; #prints &quot;1\n&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#X-and-Y">X and Y</a>, <a href="#X-&-Y">X & Y</a>
</p>
<h2 id="X-||-Y">X || Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#C-style-Logical-Or"><em>C-style Logical Or</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the high-precedence logical or operator. It returns the X if X evaluates to true, otherwise it returns Y.
</p>
<p>
It binds more tightly than the low-precedence logical or operator:
</p>
<pre>
my $x = 5 || 4; # is equivalent to my $x = (5 || 4);
</pre>
<p>
whereas:
</p>
<pre>
my $y = 5 or 4; # is equivalent to (my $x = 5) or 4;
</pre>
<p>
It is most commonly used in conditional statements such as <code>if</code>, <code>unless</code>, <code>while</code>. It was used in the recent past to create default values:
</p>
<pre>
my %config = get_config();
#set $x to $config{x} unless it is false, in which case set it to 5
my $x = $config{x} || 5;
</pre>
<p>
but this use has the drawback of not respecting a value of 0 or 0.0, since they both evaluate to false. The // operator is now recommend for this purpose since it tests if X is defined, not if it is true.
</p>
<h3>Example</h3>
<pre>
my $w = &quot;&quot;;
my $x = 0;
my $y = 1;
my $z = &quot;foo&quot;;
print $w || $x, &quot;\n&quot;; #prints &quot;0\n&quot;;
print $x || $w, &quot;\n&quot;; #prints &quot;\n&quot;;
print $w || $y, &quot;\n&quot;; #prints &quot;1\n&quot;
print $x || $y, &quot;\n&quot;; #prints &quot;1\n&quot;
print $y || $z, &quot;\n&quot;; #prints &quot;1\n&quot;
print $z || $y, &quot;\n&quot;; #prints &quot;foo\n&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#X-or-Y">X or Y</a>, <a href="#X-xor-Y">X xor Y</a>, <a href="#X-|-Y">X | Y</a>, <a href="#X-//-Y">X // Y</a>, and <a href="#X-^-Y">X ^ Y</a>
</p>
<h2 id="X-//-Y">X // Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#C-style-Logical-Defined-Or"><em>C-style Logical Defined-Or</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the high-precedence logical defined-or. It returns X if X is defined, otherwise it returns Y. This operator is only available if you have enabled 5.10 features (using the <a href="http://perldoc.perl.org/feature.html#">feature</a> pragma or <code>use 5.10</code>).
</p>
<p>
It is most commonly used to create default values:
</p>
<pre>
my %config = get_config();
#set $x to $config{x} if it is defined, otherwise set it to 5
my $x = $config{x} // 5;
</pre>
<h3>Example</h3>
<pre>
my $x;
my $y = 0;
my $z = 5;
print $x // $y, &quot;\n&quot;; #prints 0
print $y // $z, &quot;\n&quot;; #prints 0
print $z // $y, &quot;\n&quot;; #prints 5
</pre>
<h3>See also</h3>
<p>
<a href="#X-or-Y">X or Y</a>, <a href="#X-xor-Y">X xor Y</a>, <a href="#X-||-Y">X || Y</a>, <a href="#X-|-Y">X | Y</a>, and <a href="#X-^-Y">X ^ Y</a>
</p>
<h2 id="X-..-Y">X .. Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Range-Operators"><em>Range Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
Depending on context, this is either the range operator (if it is list context) or the flip-flop operator (if it is in scalar context).
</p>
<p>
The range operator creates a list starting with X and ending with Y (i.e. it is inclusive). If Y is less than X then an empty list is returned. If both X and Y are strings, then the auto-magical behavior of <a href="#X++">X++</a> is used to generate the list.
</p>
<p>
The flip-flop operator returns false as long as X is false, once X becomes true it returns true until <em>after</em> Y is true, at which time it returns false. Each flip-flop operator keeps track of its own state separately from the other flip-flop operators.
</p>
<p>
Note: it is possible for both the X and Y tests to be true at the same time, in which case it will return true and then false on the next test.
</p>
<h3>Example</h3>
<pre>
my @list = 0 .. 5; #@list is now (0, 1, 2, 3, 4, 5)
my @az = &quot;a&quot; .. &quot;z&quot;; #@az is now the lowercase ASCII alphabet
prints &quot;4\n&quot;, &quot;5\n&quot;, &quot;6\n&quot;, &quot;7\n&quot;, and &quot;8\n&quot;
for my $i (0 .. 10) {
#start printing when $i is 4 and stop after $i is 8
if ($i == 4 .. $i == 8) {
print &quot;$i\n&quot;;
}
}
#prints &quot;4\n&quot;
for my $i (0 .. 10) {
#start printing when $i is 4 and stop after $i is 4
if ($i == 4 .. $i == 8) {
print &quot;$i\n&quot;;
}
}
</pre>
<h3>See also</h3>
<p>
<a href="#X-...-Y">X ... Y</a>
</p>
<h2 id="X-...-Y">X ... Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Range-Operators"><em>Range Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is another form of the range/flip flop operator (<a href="#X-..-Y">X .. Y</a>). Its meaning is context dependent.
</p>
<p>
In list context it creates a list starting with X and ending with Y (i.e. it is inclusive). If Y is less than X then an empty list is returned. If both X and Y are strings, then the auto-magical behavior of <a href="#X++">X++</a> is used to generate the list.
</p>
<p>
In scalar context it returns false as long as X is false, once X becomes true it returns true until <em>after</em> Y is true, at which time it returns false. Each flip-flop operator keeps track of its own state separately from the other flip-flop operators. It only evaluates X or Y each time it called, unlike <a href="#X-..-Y">X .. Y</a> which evaluates both X and Y each time it is called.
</p>
<h3>Example</h3>
<pre>
my @list = 0 ... 5; #@list is now (0, 1, 2, 3, 4, 5)
my @az = &quot;a&quot; ... &quot;z&quot;; #@az is now the lowercase ASCII alphabet
prints &quot;4\n&quot;, &quot;5\n&quot;, &quot;6\n&quot;, &quot;7\n&quot;, and &quot;8\n&quot;
for my $i (0 ... 10) {
#start printing when $i is 4 and stop after $i is 8
if ($i == 4 ... $i == 8) {
print &quot;$i\n&quot;;
}
}
#prints &quot;4\n&quot;, &quot;5\n&quot;, &quot;6\n&quot;, &quot;7\n&quot;, &quot;8\n&quot;, &quot;9\n&quot;, and &quot;10\n&quot;
for my $i (0 ... 10) {
#start printing when $i is 4 and stop after $i is 4 a second time
if ($i == 4 ... $i == 8) {
print &quot;$i\n&quot;;
}
}
</pre>
<h3>See also</h3>
<p>
<a href="#X-..-Y">X .. Y</a>
</p>
<h2 id="X-?-Y-:-Z">X ? Y : Z</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Conditional-Operators"><em>Conditional Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the conditional operator. It works much like an if-then-else. If the X is true then Y is evaluated and returned otherwise Z is evaluated and returned.
</p>
<p>
The context it is called in propagates to Y and Z, so if the operator is called in scalar context and X is true then Y will be evaluated in scalar context.
</p>
<p>
The result of the operator is a valid lvalue (i.e. it can be assigned to). Note, normal rules about lvalues (e.g. you can&#39;t assign to constants) still apply.
</p>
<h3>Example</h3>
<pre>
#simple implementation of max
sub max {
my ($m, $n) = @_;
return $m &gt;= $n ? $m : $n;
}
my $x = max 5, 4; #$x is now 5
my $y = max 4, 5; #$y is now 5
my @a = $x == $y ? (1, 2, 3) : (4, 5, 6); #@a is now (1, 2, 3)
my @b = $x != $y ? (1, 2, 3) : (4, 5, 6); #@b is now (4, 5, 6)
($x == $y ? $x : $y) = 15; #$x is now 15
($x == $y ? $x : $y) = 15; #$y is now 15
</pre>
<h3>See also</h3>
<p>
<a href="http://perldoc.perl.org/perlsyn.html#Compound-Statements"><em>Compound-Statements</em> in perlsyn</a>
</p>
<h2 id="X-=-Y">X = Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
If X is a scalar, then this is the assignment operator. It assigns Y to X. The act of assigning creates an lvalue, that is the result of an assignment can be used in places where you would normally use a plain variable:
</p>
<pre>
my $str = &quot;foobar&quot;;
(my $modified = $str) =~ s/foo/bar/; #the substitution affects $modified
</pre>
<p>
If X is a list, then this is the list assignment operator and it provides list context to Y. The first item in the list Y is assigned to the first item in list X, the second to the second, and so on. If placed in scalar context, the return value of list assignment is the number of items in the second list. If placed in list context it returns the list X (after the assignment has taken place).
</p>
<h3>Example</h3>
<pre>
my $x = 5; #$x is now 5
my $y = 6; #$y is now 6
($x, $y) = ($y, $x); #$x is now 6 and $y is now 5
my $i = my $j = my $k = 10; #$i, $j, and $k are now all 10
my $m = my ($n, $o) = (&quot;a&quot;, &quot;b&quot;, &quot;c&quot;) #$m is now 3
</pre>
<h2 id="X-**=-Y">X **= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the exponentiation assignment operator. It is equivalent to
</p>
<pre>
X = X ** Y
</pre>
<p>
That is it raises the value X to the Yth power and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x **= $y; #$x is now 2 ** 8 or 256
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-**-Y">X ** Y</a>
</p>
<h2 id="X-+=-Y">X += Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the addition assignment operator. It is equivalent to
</p>
<pre>
X = X + Y
</pre>
<p>
That is it adds X and Y together and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x += $y; #$x is now 2 + 8 or 10
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-+-Y">X + Y</a>
</p>
<h2 id="X--=-Y">X -= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the subtraction assignment operator. It is equivalent to
</p>
<pre>
X = X - Y
</pre>
<p>
That is it subtracts Y from X and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x -= $y; #$x is now 2 - 8 or -6
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X---Y">X - Y</a>
</p>
<h2 id="X-.=-Y">X .= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the concatenation assignment operator. It is equivalent to
</p>
<pre>
X = X . Y
</pre>
<p>
That is it joins the strings X and Y and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x .= $y; #$x is now 2 . 8 or &quot;28&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-.-Y">X . Y</a>
</p>
<h2 id="X-*=-Y">X *= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the multiplication assignment operator. It is equivalent to
</p>
<pre>
X = X * Y
</pre>
<p>
That is it multiplies X by Y and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x *= $y; #$x is now 2 * 8 or 16
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-*-Y">X * Y</a>
</p>
<h2 id="X-/=-Y">X /= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the division assignment operator. It is equivalent to
</p>
<pre>
X = X / Y
</pre>
<p>
That is it divides X by Y and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<p>
Warning: If Y is 0 or evaluates to 0 the program will die with a message like <code>Illegal division by zero</code>.
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x /= $y; #$x is now 2 / 8 or 0.25
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-/-Y">X / Y</a>
</p>
<h2 id="X-%=-Y">X %= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the modulo assignment operator. It is equivalent to
</p>
<pre>
X = X % Y
</pre>
<p>
That is it computes the remainder of X divided by Y and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<p>
Warning: If Y is 0 or evaluates to 0 the program will die with a message like <code>Illegal modulus zero</code>.
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x %= $y; #$x is now 2 % 8 or 2
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-%-Y">X % Y</a>
</p>
<h2 id="X-x=-Y">X x= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the scalar repetition assignment operator. It is equivalent to
</p>
<pre>
X = X x Y
</pre>
<p>
That is it creates a string made up of X repeated Y times and assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<p>
Note: this only works for the scalar repetition operator; the list repetition operator (<a href="#(X)-x-Y">(X) x Y</a>) will not work in this context.
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x x= $y; #$x is now 2 x 8 or &quot;22222222&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-x-Y">X x Y</a>
</p>
<h2 id="X-&=-Y">X &= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the bitwise and assignment operator. It is equivalent to
</p>
<pre>
X = X &amp; Y
</pre>
<p>
That is it ands together X and Y and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x &amp;= $y; #$x is now 2 &amp; 8 or 0
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-&-Y">X & Y</a>
</p>
<h2 id="X-|=-Y">X |= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the bitwise or assignment operator. It is equivalent to
</p>
<pre>
X = X | Y
</pre>
<p>
That is it ors together X and Y and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x |= $y; #$x is now 2 &amp; 8 or 10
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-|-Y">X | Y</a>
</p>
<h2 id="X-^=-Y">X ^= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the bitwise xor assignment operator. It is equivalent to
</p>
<pre>
X = X ^ Y
</pre>
<p>
That is it xors together X and Y and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x ^= $y; #$x is now 2 &amp; 8 or 10
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-^-Y">X ^ Y</a>
</p>
<h2 id="X-<<=-Y">X <<= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the left bit-shift assignment operator. It is equivalent to
</p>
<pre>
X = X &lt;&lt; Y
</pre>
<p>
That is it bit-shifts X Y places to the left and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x &lt;&lt;= $y; #$x is now 2 &lt;&lt; 8 or 512
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-<<-Y">X << Y</a>
</p>
<h2 id="X->>=-Y">X >>= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the right bit-shift assignment operator. It is equivalent to
</p>
<pre>
X = X &gt;&gt; Y
</pre>
<p>
That is it bit-shifts X Y places to the right and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<h3>Example</h3>
<pre>
my $x = 8;
my $y = 2;
$x &amp;= $y; #$x is now 8 &amp; 2 or 2
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X->>-Y">X >> Y</a>
</p>
<h2 id="X-&&=-Y">X &&= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the logical and assignment operator. It is equivalent to
</p>
<pre>
X = X &amp;&amp; Y
</pre>
<p>
That is it assigns X to itself if X evaluates to true, otherwise it assigns Y to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
$x &amp;&amp;= $y; #$x is now 2 &amp;&amp; 8 or 8
$x &amp;&amp;= 0; #$x is now 8 &amp;&amp; 0 or 0
$x &amp;&amp;= 8; #$x is now 0 &amp;&amp; 8 or 0
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a> and <a href="#X-&&-Y">X && Y</a>
</p>
<h2 id="X-||=-Y">X ||= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the logical or assignment operator. It is equivalent to
</p>
<pre>
X = X || Y
</pre>
<p>
That is it logically ors together X and Y and then assigns the result to X. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to). It was often used in the past to assign a value if the variable did not already have a value:
</p>
<pre>
my $x;
#intervening code that might set $x or might leave it undefined
$x ||= 10; #make sure $x gets set to a default value
</pre>
<p>
This has a problem though: if <code>$x</code> is <code>0</code> or <code>&quot;&quot;</code> then it will get overwritten with <code>10</code>. The defined-or assignment operator (<a href="#X-//=-Y">X //= Y</a>) does not have this problem and should, generally, be used for this purpose instead. Of course, if you desire any false value be overwritten, then this is the right operator to use.
</p>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
my $z;
$x ||= $y; #$x is now 2 || 8 or 2
$y ||= $x; #$y is now 8 || 2 or 8
my $z ||= $x + $y; #$z is now undef || (2 + 8) or 10
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a>, <a href="#X-||-Y">X || Y</a>, and <a href="#X-//=-Y">X //= Y</a>
</p>
<h2 id="X-//=-Y">X //= Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Assignment-Operators"><em>Assignment Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the defined-or assignment operator. It is equivalent to
</p>
<pre>
X = X // Y
</pre>
<p>
It assigns Y to X if X is not already defined. This means that X must be a valid lvalue (i.e. it must be something that can be assigned to).
</p>
<p>
It is commonly used to ensure that a variable has a value:
</p>
<pre>
my $x;
#intervening code that might set $x or might leave it undefined
$x //= 10; #make sure $x gets set to a default value
</pre>
<h3>Example</h3>
<pre>
my $x = 2;
my $y = 8;
my $z;
$x //= $y; #$x is now 2 // 8 or 2
$z //= $x; #$z is now undef // 2 or 2
</pre>
<h3>See also</h3>
<p>
<a href="#X-=-Y">X = Y</a>, <a href="#X-//-Y">X // Y</a>, <a href="#X-||-Y">X || Y</a>
</p>
<h2 id="X,-Y">X, Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Comma-Operators"><em>Comma Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the comma operator. In list context it builds a list. In scalar context it evaluates each item but the last in void context, and then evaluates the last in scalar context and returns it.
</p>
<p>
Due to the fact that the assignment operator has higher precedence, you must surround the list with parentheses. For example,
</p>
<pre>
my @list = 1, 2, 3;
</pre>
<p>
says the same thing as
</p>
<pre>
(my @list = 1), 2, 3
</pre>
<p>
To get the desired behaviour you must say
</p>
<pre>
my @list = (1, 2, 3);
</pre>
<p>
Function calls, on the other hand, have a lower precedence, so you can say
</p>
<pre>
print 1, 2, 3, &quot;\n&quot;;
</pre>
<p>
A trailing comma does not add a new element to a list, to the lists <code>(1,2,3)</code> and <code>(1,2,3,)</code>) are identical.
</p>
<h3>Example</h3>
<pre>
my @a = (1, 2, 3); #@a is now (1, 2, 3)
my $x = (&quot;a&quot;, &quot;b&quot;, &quot;c&quot;); #$x is now &quot;c&quot;
my $y = (++$x, ++$x, ++$x); #$y is now &quot;f&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#X-=>-Y">X => Y</a>
</p>
<h2 id="X-=>-Y">X => Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Comma-Operators"><em>Comma Operators</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the fat comma operator. It behaves much in the same way as the comma operator (creates lists in list context, returns the last value in scalar context), but it has a special property: it stringifies X if X is a bareword (i.e. it matches <code>/^[a-zA-Z_]\w+$/</code>). It is most often used when creating hashes because the arrow like appearance makes it easy to identify the key versus the value and the auto-stringifing property makes the keys look cleaner:
</p>
<pre>
my %hash = (
key1 =&gt; &quot;value1&quot;,
key2 =&gt; &quot;value2&quot;,
key3 =&gt; &quot;value3&quot;,
);
</pre>
<p>
That statement is functionally identical to
</p>
<pre>
my %hash = (
&quot;key1&quot;, &quot;value1&quot;,
&quot;key2&quot;, &quot;value2&quot;,
&quot;key3&quot;, &quot;value3&quot;,
);
</pre>
<h3>Example</h3>
<pre>
#%x will contain the list (&quot;a&quot;, 1, &quot;b&quot;, 2, &quot;c&quot;, 3)
my %x = (
a =&gt; 1,
b =&gt; 2,
c =&gt; 3,
);
#%y will contain the list (&quot;key with spaces&quot;, 1, &quot;b&quot;, 1, &quot;c&quot;, 1)
my %y = (
&quot;key with spaces&quot; =&gt; 1,
b =&gt; 1,
c =&gt; 1,
);
</pre>
<h3>See also</h3>
<p>
<a href="#X,-Y">X, Y</a>
</p>
<h2 id="not-X">not X</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Logical-Not"><em>Logical Not</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the low-precedence logical negation operator. It performs logical negation, i.e., &quot;not&quot;. It returns an empty string if X is true, otherwise it returns <code>1</code>. There is a high-precedence version: <code>!</code>.
</p>
<h3>Example</h3>
<pre>
my $m = not 5; #$m is now the empty string (&quot;&quot;)
my $n = not 0; #$n is now 1
my $o = not &quot;&quot;; #$o is now 1
my $p = not undef; #$p is now 1
</pre>
<h3>See also</h3>
<p>
<a href="#!X">!X</a>
</p>
<h2 id="X-and-Y">X and Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Logical-And"><em>Logical And</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the low-precedence logical and operator. It evaluates X, and if it is false it returns the value of X. If X evaluates to true it evaluates Y and returns its value.
</p>
<p>
It binds less tightly than the high-precedence logical and operator:
</p>
<pre>
my $y = 5 and 4; # is equivalent to (my $x = 5) and 4;
</pre>
<p>
whereas:
</p>
<pre>
my $x = 5 &amp;&amp; 4; # is equivalent to my $x = (5 &amp;&amp; 4);
</pre>
<p>
It is most commonly used in conditional statements such as <code>if</code>, <code>unless</code>, <code>while</code>. But it is also occasionally used for its short-circuiting affect:
</p>
<pre>
do_this() and do_that() and do_last();
</pre>
<p>
is functionally the same as
</p>
<pre>
if (do_this()) {
if (do_that()) {
do_last();
}
}
</pre>
<h3>Example</h3>
<pre>
my $w = &quot;&quot;;
my $x = 0;
my $y = 1;
my $z = &quot;foo&quot;;
#not the use of parentheses vs this example in &amp;&amp;
print(($w and $y), &quot;\n&quot;); #prints &quot;\n&quot;
print(($x and $y), &quot;\n&quot;); #prints &quot;0\n&quot;
print(($y and $z), &quot;\n&quot;); #prints &quot;foo\n&quot;
print(($z and $y), &quot;\n&quot;); #prints &quot;1\n&quot;
</pre>
<h3>See also</h3>
<p>
<a href="#X-&&-Y">X && Y</a> and <a href="#X-&-Y">X & Y</a>
</p>
<h2 id="X-or-Y">X or Y</h2>
<h3>Class</h3>
<p>
This belongs to <a href="http://perldoc.perl.org/perlop.html#Logical-or,-Defined-or,-and-Exclusive-Or"><em>Logical or, Defined or, and Exclusive Or</em> in perlop</a>.
</p>
<h3>Description</h3>
<p>
This is the low-precedence logical or operator. It evaluates X, and if it is true it returns the value of X. If X evaluates to false it evaluates Y and returns its value.
</p>
<p>
It binds less tightly than the high-precedence logical or operator:
</p>