in reply to Re: What are the brackets in this for ?
in thread What are the brackets in this for ?

Not only that, but you can leave off the parens for the prototyped sub. Otherwise you would have to write FOO() instead of FOO.

This is usually done in situations where you would use #define in a C program to introduce a constant. In C, you would write

#define FOO 1

and then you could use FOO in your program and it would be the same as if you had written a literal 1. Creating a Perl sub with a prototype lets you write FOO, which looks like a constant, instead of FOO(), which looks like a sub call.

Replies are listed 'Best First'.
Re^3: What are the brackets in this for ?
by gellyfish (Monsignor) on May 22, 2006 at 14:27 UTC

    It's not quite as cut and dried as that. The prototyping makes no difference if the subroutine is not introduced before it is first referenced, you will still get the "Bareword" error when using strict (and if you are not using strict the sub name will be taken as a string.) If you define the subroutine first or make a forward declaration (e.g sub FOO;) then you can use it without the parentheses regardless of the prototyping.

    /J\

Re^3: What are the brackets in this for ?
by blazar (Canon) on May 22, 2006 at 14:24 UTC
    Not only that, but you can leave off the parens for the prototyped sub. Otherwise you would have to write FOO() instead of FOO.

    Really?

    #!/usr/bin/perl -l use strict; use warnings; sub FOO { @_? 1+shift : print 'Foo'; } FOO for 1..FOO FOO; __END__