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

Fair enough. But, now I'm curious. Since Perl doesn't have type checking, what good does declaring the subroutine get you? Why is perl not able to parse the file, say "hey, chas has subroutines foo, bar, and baz, so if I see them referenced, I'll use them"? Just seems odd to me.

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

  • Comment on Re^3: Warning for "unused sub declarations"?

Replies are listed 'Best First'.
Re^4: Warning for "unused sub declarations"?
by chas (Priest) on May 20, 2005 at 00:49 UTC
    Reasonable question! I don't know enough about how the parsing/compiling takes place to say. But I suppose it may save some time (i.e. decrease the number of passes) if it is not necessary to look ahead for sub defs. I'll bet someone else around here knows, though. BTW, I usually do like you do and put sub defs at the end (and call with &.) My previous response was just an answer to why someone might declare subs before using; I used to predeclare, but lately it seems more organized to have all the subs defined/declared in just one place (and that outweighs the disadvantages most of the time.)
    chas
      BTW, I usually do like you do and put sub defs at the end (and call with &.)
      Sorry for the repetition, but repetita iuvant. You can put your sub defs wherever you want. But you should never ever call them with & unless you know what you're doing. perlsub will explain you why far better than I could.