Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: subroutine prototypes still bad?

by Zaxo (Archbishop)
on Jun 13, 2007 at 00:28 UTC ( [id://620852]=note: print w/replies, xml ) Need Help??


in reply to Re^2: subroutine prototypes still bad?
in thread subroutine prototypes still bad?

Yes, if they are prototyped. Otherwise, no.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^4: subroutine prototypes still bad?
by Anonymous Monk on Jun 13, 2007 at 00:36 UTC
    Don't you mean the converse? Placing prototypes before subroutine calls means the subroutine definition can occur much later, whereas not using prototypes means that subroutine definitions much be encountered prior to those subroutines being called. Not to be pedantic, I'm simply trying to understand the ramifications of warnings & strict.
      Aha. You're not talking about prototyping at all. You're talking about forward declarations. (See also: prototypes don't do what people expect them to do).

      A prototype in perl can be specified at a subroutine declaration to indicate special handling of parameters.

      A forward declaration is just there to signal to the compiler that a given name is a subroutine that will be defined later: update: the following code does not use prototypes

      #!/usr/bin/perl -w use strict; sub bla; # a forward declaration bla; # <--- call the bla routine sub bla { print "Bla!\n"; }
      If bla is not declared at the <----- point the bareword "bla" will be interpreted as a STRING. That's almost never what you want and that's why strict complains if you comment out the forward declaration.

      Note that you can still call bla as bla() without needing to declare sub bla beforehand.

      Prototypes are not really related to this, except that in order for them to work they must also be known to the compiler before it compiles the first call, so you can also use them in forward declarations.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://620852]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found