Re: Sub routine location



sunckell wrote:
> Thanks for the input...

Who are you thanking? For what input? Please quote some context in
your replies. Please see the Posting Guidelines that are posted here
twice a week for more good advice.

> As for "MAIN" if I make a syntax error in my subroutine somewhere, i
> have seen errors that resemble..
>
> error at some line number in &subroutine::main.
>
> Or something similar. I am assuming main is section of script that
> does the calling to subroutines etc. I guess I am wrong?

Difficult to know without a more precise example. That particular form
of an error message isn't jumping out at me as immediately familiar.
Perhaps you could contrive an example which generates this sort of
error message, and then copy and paste it directly?

> I thought I would ask this becuase I have noticed certian warnings (
> I'll have to test this since I am remebering what I have seen) when
> subroutines are at the bottom of the script and I call them just by
> subroutine_name($var1,$var2) and not like
> &subroutine_name($var1,$var2).

My guess would be that this relates to one of the two "exceptions" I
noted in my first reply to your initial question - When your
subroutines are declared after being called, prototypes are not
enforced, and you get a warning telling you about it. When you call a
subroutine using the & in front of the name, that tells perl to disable
prototype checking. Perl assumes you are specifically asking for that
feature, and so doesn't bother warning you that it can't check the
prototypes in the first place.

A good rule of thumb is to never use & unless you know exactly what
reason you have to use it. 99% of the time, you don't have any reason
to.

Paul Lalli

.



Relevant Pages

  • Re: Critique
    ... Having separate prototypes at ... >> allows me to always have mainas the first function. ... >> redundancy. ... > to create the various subroutines. ...
    (comp.lang.c)
  • Re: Subroutines with & (was: Re: returning references, etc.)
    ... >> Don't call subroutines using the & in front of the subroutine name ... > but lately I've had the compiler sometimes complain about the wrong ... If you are using prototypes, ... Sinan Unur ...
    (comp.lang.perl.misc)
  • Re: Subroutines with & (was: Re: returning references, etc.)
    ... >> unless you know what that does and you want that added functionality. ... Which overrides prototypes, ie. it is in Paul's "one percent". ... There are no subroutines involved with regular expressions, ...
    (comp.lang.perl.misc)
  • Re: Newbie question on ON WARNING
    ... When one issues a second ON WARNING in a procedure, ... DCL is no "real" programming language. ... Are we discussing GOSUB subroutines or CALL subroutines? ...
    (comp.os.vms)
  • Re: Critique
    ... Having separate prototypes ... I use the "prototypes, main, ... > subroutines" layout, and I have not had any problems with it. ... > update the prototype, but if I do not, I get a compilation error. ...
    (comp.lang.c)