Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Functions Signatures

by nofernandes (Beadle)
on Jul 17, 2003 at 12:04 UTC ( #275185=perlquestion: print w/replies, xml ) Need Help??

nofernandes has asked for the wisdom of the Perl Monks concerning the following question:


Does someone knows how can i declare a function signature at the start of the code!? Like is done in C or Java??


If i had this funcion:

sub Hello{ my($text)=@_; print $text; }

How can i show at the beggining of the file that this function exists without comments of course..

Something like this:

sub Hello($text); $a="Hello World"; Hello($a); sub Hello{ my($text)=@_; print $text; }

Does anyone knows? Is it possible?


Replies are listed 'Best First'.
Re: Functions Signatures
by Abigail-II (Bishop) on Jul 17, 2003 at 12:10 UTC
    You can always declare subs:
    sub Hello;

    It doesn't show what kind of arguments it expects, because the definition of the sub doesn't see so either. You could use prototypes, but be aware of the results. Prototypes aren't as useful as you may think. If you use prototypes, write:

    sub Hello ($);

    but then you have to repeat that prototype when defining the function:

    sub Hello ($) { my ($text) = @_; print $text; }


      In addition, you can also

      use subs qw( sub_name_one sub_name_two etc );

      "Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."

      Ok.. but so i cannot show the arguments of the file?

      Ok thank you very much!!

        Arguments of the file? What do you mean by that?


Re: Functions Signatures
by broquaint (Abbot) on Jul 17, 2003 at 12:14 UTC
Re: Functions Signatures
by Nkuvu (Priest) on Jul 17, 2003 at 15:39 UTC

    Question's been answered, but I have one of my own. Um, why would you feel the need to do this?

    When I write scripts I put all subroutines at the end of the script, and don't have any problems calling them in the main portion of the script.

    Maybe it's just for developer information so they don't have to scroll to where your subs are to see what's available?

      Maybe it's just for developer information so they don't have to scroll to where your subs are to see what's available?

      That's what comments are for. If you insist, put a set of comments in the beginning of your code that provide an "index" to the functions you define.

      Better yet, make it POD so you can do neat things later on like generate MAN pages, HTML, etc.

      Peter L. BergholdBrewer of Belgian Ales
      Unix Professional
        Well, yes, that would be my approach. But it was the best idea I could come up with for doing this.
      If they're that lazy that they won't use a search function .....

      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://275185]
Approved by broquaint
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2021-10-22 16:26 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (85 votes). Check out past polls.