Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: What's so bad about &function(...)?

by Perl Mouse (Chaplain)
on Dec 08, 2005 at 20:27 UTC ( [id://515364]=note: print w/replies, xml ) Need Help??


in reply to Re: What's so bad about &function(...)?
in thread What's so bad about &function(...)?

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.
Perl --((8:>*

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://515364]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-29 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found