in reply to Re: Constant subroutines thoughts
in thread Constant subroutines thoughts

I see your point, and agree with you completely.

Why I used constant subroutines instead of doing use constant FOO => 'bar';? Because, as I saw everywhere else sub SOME_CONST{0}, and only now I discovered details about this.

Additionally I want to note that use constant FOO => 'bar'; internally does things similar to sub FOO(){'bar'} - I checked this right now.

Most important point of my initial message - that my places in programs, such as do{'a lot of debug stuff'} if DEBUG were NOT optimized away, whereas adding a prototype '()' to 'sub DEBUG' makes them to be optimized away!

Courage, the Cowardly Dog.
PS. Something fishy is going on there, or my name is Vadim Konovalov. And it's not.

Replies are listed 'Best First'.
Re^3: Constant subroutines thoughts
by tadman (Prior) on Jun 09, 2002 at 13:31 UTC
    It would be nice if you could declare inline functions explicitly rather than implicitly using this empty bracket "trick". I had no idea that Perl did this sort of magic for you under special circumstances. Maybe I haven't read enough of the latest Camel Book, because the older one didn't seem to make much of a big deal about it.

    I think the reason I was so befuddled by it in the first place is because it didn't make any sense that Perl would do that sort of thing, I mean, other languages you've got to tell them to do this for you.
      Seems like I fallen into the same sort of confusion as you did. Anyway, as I mentioned, this is documented in "perlsub.pod", section "Constant Functions", and, if you're not pleased by bracket trick, then use "constant" module which does the same thing behind the scenes, and will be more portable just in case such mechanics will change...

      Courage, the Cowardly Dog.
      PS. Something fishy is going on there, or my name is Vadim Konovalov. And it's not.