Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2015-11-25 07:08 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (672 votes), past polls