Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Virtually every time you see <code>&amp;</code> outside of <code>\&amp;foo</code> and <code>EXRP &amp;&amp; EXPR</code>, it's an error.</p> <hr> <ul> <li><p><code>&amp;foo(...)</code> is the same as <code>foo(...)</code> except <code>foo</code>'s prototype will be ignored.</p> <pre><code>sub foo(&amp;@) { ... } # Cause foo to takes a BLOCK as its first arg foo { ... } ...; &amp;foo(sub { ... }, ...); # Same thing. </code></pre> <p>Only subroutines (not operators) will be called by <code>&amp;foo(...)</code>.</p> <pre><code>sub print { ... } print(...); # Calls the print builtin &amp;print(...); # Calls the print sub. </code></pre> <p>You'll probably never need to use this feature in your entire programming career. If you see it used, it's surely someone using <code>&amp;</code> when they shouldn't.</p></li> <li><p><code>&amp;foo</code> is similar to <code>&amp;foo(@_)</code>. The difference is that changes to <code>@_</code> in <code>foo</code> affects the current sub's <code>@_</code>.</p> <p>You'll probably never need to use this feature in your entire programming career. If you see it used, it's surely someone using <code>&amp;</code> when they shouldn't or a foolish attempt at optimization. However, the following is pretty elegant:</p> <pre><code>sub log_info { unshift @_, 'info'; &amp;log } sub log_warn { unshift @_, 'warn'; &amp;log } sub log_error { unshift @_, 'error'; &amp;log } </code></pre></li> <li><p><code>goto &amp;foo</code> is similar to <code>&amp;foo</code>, except the current subroutine is removed from the call stack first. This will cause it to not show up in stack traces, for example.</p> <p>You'll probably never need to use this feature in your entire programming career. If you see it used, it's surely a foolish attempt at optimization.</p> <pre><code>sub log_info { unshift @_, 'info'; goto &amp;log; } # These are slower than sub log_warn { unshift @_, 'warn'; goto &amp;log; } # not using goto, but maybe sub log_error { unshift @_, 'error'; goto &amp;log; } # maybe log uses caller()? </code></pre></li> <li><p><code>$&amp;</code> contains what the last regex expression match matched. Before 5.20, using this causes every regex in your entire interpreter to become slower (if they have no captures), so don't use this.</p> <pre><code>print $&amp; if /fo+/; # Bad before 5.20 print $MATCH if /fo+/; # Bad (Same thing. Requires "use English;") print ${^MATCH} if /fo+/p; # Ok (Requires Perl 5.10) print $1 if /(fo+)/; # Ok </code></pre></li> <li><p><code>defined &amp;foo</code> is a perfectly legitimate way of checking if a subroutine exists, but it's not something you'll likely ever need. There's also <code>exists &amp;foo</code> is similar, but not as useful.</p></li> <li><p><code>EXPR &amp; EXPR</code> is the bitwise AND operator. This is used when dealing with low-level systems that store multiple pieces of information in a single word.</p> <pre><code>system($cmd); die "Can't execute command: $!\n" if $? == -1; die "Child kill by ".($? &amp; 0x7F)."\n" if $? &amp; 0x7F; die "Child exited with ".($? &gt;&gt; 8)."\n" if $? &gt;&gt; 8; </code></pre></li> <li><p><code>&amp;{ EXPR }()</code> (and <code>&amp;$ref()</code>) is a subroutine call via a reference. This is a perfectly acceptable and somewhat common thing to do, though I prefer the <code>$ref-&gt;()</code> syntax. Example in next item.</p></li> <li><p><code>\&amp;foo</code> takes a reference to subroutine <code>foo</code>. This is a perfectly acceptable and somewhat common thing to do.</p> <pre><code>my %dispatch = ( foo =&gt; \&amp;foo, bar =&gt; \&amp;bar, ); my $handler = $dispatch{$cmd} or die; $handler-&gt;(); # Same: &amp;{ $handler }(); # Same: &amp;$handler(); </code></pre></li> <li><p><code>EXPR &amp;&amp; EXPR</code> is the boolean AND operator. I'm sure you're familiar with this extremely common operator.</p> <pre><code>if (0 &lt;= $x &amp;&amp; $x &lt;= 100) { ... } </code></pre></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload