Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: What is the point of the & sigil for function refs?

by grinder (Bishop)
on Feb 04, 2005 at 13:28 UTC ( #428051=note: print w/ replies, xml ) Need Help??


in reply to What is the point of the & / ampersand sigil for function refs?

Is there ever a scenario when it's preferrable to use the &

There is one dramatic difference that occurs when you call the function without a parameter list:

#! /usr/local/bin/perl -w use strict; sub inner { print " inner: $_\n" for @_; } sub outer { print "outer: $_\n" for @_; inner; print "\n"; } sub outer_amp { print "outer_amp: $_\n" for @_; &inner; print "\n"; } outer( qw/ vroon gukguk faba / ); outer_amp( qw/ foomp tweedle zachitty / ); __RESULTS__ outer: vroon outer: gukguk outer: faba outer_amp: foomp outer_amp: tweedle outer_amp: zachitty inner: foomp inner: tweedle inner: zachitty

When using the &inner variant, whatever remains of @_ in the calling routine is passed to the called routine. The only time it's really useful is when doing out-of-the-ordinary stuff like autoloading. In general you should avoid it. It leads to bad surprises

PS: metasyntactic function call arguments courtesy of BooK's Acme::MetaSyntactic module, the donmartin theme.

- another intruder with the mooring in the heart of the Perl


Comment on Re: What is the point of the & sigil for function refs?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2015-07-03 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (55 votes), past polls