in reply to Re^2: Warning for "unused sub declarations"?
in thread Warning for "unused sub declarations"?

If the sub isn't declared or defined before use, then you can't call it like a builtin - without & and parentheses around the arguments. That's the main disadvantage for me.
Huh?!? You're joking? Indeed I do declare my subs to be able to call them without parentheses - fair enough. But it is never stressed enough that in Perl5 (as opposed to Perl4 and previous versions) the &-form of of sub call should never ever be used unless you really need it, i.e. you do know what you're doing. See perlsub.
  • Comment on Re^3: Warning for "unused sub declarations"?

Replies are listed 'Best First'.
Re: Warning for "unused sub declarations"?
by jonadab (Parson) on May 20, 2005 at 12:29 UTC

    It seems to me that people are over-reacting here. I don't generally like to call subs with the ampersand because IMO the code is more readable without it, but honestly, if the other poster wants to write code that calls subroutines using ampersands and parens, I don't see how that will really harm him. Yeah, it suppresses prototypes, but so what? Nobody who needs to be pointed at perlsub is using prototypes anyway.

    The only really weird wrinkle with the ampersand sigil is what happens if you also leave off the parens, but the other poster specifically said ampersand and parens, so he's not likely to run into that.


    "In adjectives, with the addition of inflectional endings, a changeable long vowel (Qamets or Tsere) in an open, propretonic syllable will reduce to Vocal Shewa. This type of change occurs when the open, pretonic syllable of the masculine singular adjective becomes propretonic with the addition of inflectional endings."  — Pratico & Van Pelt, BBHG, p68

      How are we defining "really weird"? I think that this case is pretty weird, and happens with or without parens:

      use strict; sub foo(\@;@) { shift; print @_, "\n"; }; my @arr1 = ( [1, 2], 2, 3 ); my @arr2 = (1, 2, 3); foo( @arr1, @arr2 ); &foo( @arr1, @arr2 ); __END__ 123 23123

      I'll grant you that this example is tremendously cooked, but the issue is real. As you say, the OP might be unlikely to use such prototypes, but the OP is likely to be using the code of others.

        As noted upthread, people who have to be pointed to perlsub aren't even vaguely likely to be using prototypes.
Re^4: Warning for "unused sub declarations"?
by chas (Priest) on May 20, 2005 at 12:40 UTC
    Thanks for the comment; I was aware of the possible pitfalls, but after rereading the docs, I'm rethinking the situation.
    chas
      In the meanwhile jonadab added an informed comment (Re: Warning for "unused sub declarations"?) as to why it could not be that bad after all - in your case. It is still a bad habit and should be avoided IMHO, especially since it may not do many harm, but it doesn't improve readability nor have any other immediate advantage either.