The ampersand is ambiguous and can be interpreted by perl as bitwise AND in certain contexts. Since it is not necessary, it is better to always omit the &.
Sounds profound, and it got you quite some XP. It should have been negative XP, because your conclusion is 100% wrong.
If you you are afraid to get be bitten by the ambiguity you mention, you should avoid using bitwise and, not the sub-sigil. Because whenever perl has the option to parse an ampersand as a sub-sigil or as a bitwise and, it will parse it as the sub-sigil.
$ perl -MO=Deparse,-p -e 'sub foo {} sub bar {} bar & foo()'
sub foo {
}
sub bar {
}
bar(&foo());
-e syntax OK
Someone using sub-sigils in the above case would have gotten the binary and parsing:
perl -MO=Deparse,-p -e 'sub foo {} sub bar {} &bar & &foo()'
sub foo {
}
sub bar {
}
(&bar & &foo());
So, you have two options to avoid this ambiguity: either avoid using binary and, or to always use the sub-sigil.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|