in reply to ..."while" i do perl...

You could have a subroutine called "blah" that returns true or false:
sub blah { # Do some thinking here and give a value to $return_code return $return_code; } while (blah) { # do something really useful here }
I would categorise that as bad programming style. It will fail under "use Strict". I would prefer to show that "blah" was really a subroutine in the following way:
while (&blah) { }
or even use &blah() to show this is really a subroutine call.

A question to the true perl gurus - is there any advantage in putting in the () if there are no arguments being passed to a sub?

Replies are listed 'Best First'.
Re (tilly) 2: ..."while" i do perl...
by tilly (Archbishop) on Jan 29, 2001 at 07:54 UTC
    This comes up periodically. The answer is in perlsub, if you omit the parens there is an implicit set of arguments passed which might not be what you want. I consider this a dangerous style because even if you know about the gotcha, the person after you might not.

    Two other relevant notes. There is a promise that future Perl built-in functions will be lower case, so some people like using mixed-case function names. Also using the & is (IIRC) considerably slower than not using it.

    Personally I used to use & all of the time, but now I never do. I don't consider the arguments either way particularly convincing on that. But I always put in the parens.

Re: Re: ..."while" i do perl...
by chromatic (Archbishop) on Jan 29, 2001 at 08:00 UTC
    is there any advantage in putting in the () if there are no arguments being passed to a sub?

    The answer depends on if you prepend the sub name with & or not.

    If you do something like &blah, the sub gets the current contents of @_ as arguments (it's equivalent to blah(@_)).

    If you just do blah, then if the sub's been predeclared, it'll be called. Otherwise, it's interpreted as a bareword string. Which is probably not what you want.

    I avoid the controversy altogether by using the parenthesis as often as possible, and the ampersand only when dealing with references. I haven't found a good use for &blah, passing @_ by default, except for certain AUTOLOAD routines. It's better to avoid side-effects that might confuse someone else reading my code.

    They'll be confused enough already. *sigh*