Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by grinder (Bishop)
on Feb 04, 2005 at 13:28 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-18 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found