http://qs321.pair.com?node_id=515597


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

In the end it doesn't really matter. Like almost anything in Perl you can do it in more than one way. If you know the pitfalls with all the different options then good for you. Use whatever you want.
The fact remains though that for someone new to Perl using &foo could pose a lot more problems than not using it, so to make it easier for beginners not to walk into problems they are not aware of, rather leave it out in the code submitted here.
If they know enough about perl and read discussions like this one then they can decide to use whatever they want but be aware of the consequences.
Just my opinion.
  • Comment on Re: What's so bad about &function(...)?

Replies are listed 'Best First'.
Re^2: What's so bad about &function(...)?
by TimToady (Parson) on Dec 09, 2005 at 18:04 UTC
    Another reason it doesn't much matter is that, to make things more consistent, we're changing what it means in Perl 6. The notation no longer has anything to do with how the arguments are processed--there are now flattening operators for that. Instead, when you say &foo, you're explicitly marking "foo" as a noun rather than a verb. As a noun, it always returns a scalar reference in scalar context, and like any other reference, it is not dereferenced unless you do so explicitly. In the case of &foo, it is not called unless you say &foo() or some such.

    Interestingly, this completely removes the Perl 5 distinction between foo(1,2,3) and &foo(1,2,3). Those are handled identically in Perl 6. What changes is the meaning of bare &foo. You now always have to pass @_ explicitly if that's what you mean.

      In Perl5, if you have arguments to a function, the parenthesis are optional if you don't use the & sigil (unless of course they are needed to prevent misparsing). However, if you use &foo to call a sub, and you want to call it with arguments, the parenthesis are mandatory.

      Will you be able to do:

      &foo 1, 2, 3
      in Perl6?
      Perl --((8:>*
        Nope, Perl 6 still has to be picky about when it is expecting a term and when it is expecting an operator. It's vaguely possible we could allow
        &foo: 1, 2, 3
        however, since there are already other cases where a colon allows us to omit the parens. Can't say it's high on my list of priorities though.