Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://428051]
[Corion]: choroba: Re the one-shot thing, I also thought of bit vectors and/or indexes into one common array from the hashes, but that makes maintenance of all these indices a chorse
[Corion]: *core
[Corion]: ** chore
[Corion]: So I guess I will simply implement the linear scan first and wait with more fancy stuff until it becomes a problem
[karlgoethebier]: Lady_Aleena: ++ for "The Man Crusher Everyday"
[karlgoethebier]: this mad my day
[karlgoethebier]: no typo
[marioroy]: At the Fransiscan monastery, got stuck up high in a tree from pruning and the chainsaw with large branch fell and broke the latter, but not me fortunately. Was stuck there for a while until a firetruck came by.
[Corion]: marioroy: So you live dangerously ...
[Lady_Aleena]: s/latter/ladder/; # ? marioroy

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2017-05-29 08:30 GMT
Find Nodes?
    Voting Booth?