in reply to Re: sub execution order aka missing semicolon after sub call
in thread sub execution order aka missing semicolon after sub call

Thanks to all repliers.

The idea with the habit of adding () after all sub-calls is indeed a very good idea.

  • Comment on Re^2: sub execution order aka missing semicolon after sub call

Replies are listed 'Best First'.
Re^3: sub execution order aka missing semicolon after sub call
by johngg (Canon) on Apr 07, 2016 at 10:41 UTC
    The idea with the habit of adding () after all sub-calls is indeed a very good idea.

    There is a special case where the use of parentheses is not appropriate. If you call subB from within subA using the syntax &subB with no parentheses then the argument list of subA will be passed to subB. See this node for an example.

    The subroutine doesn't actually have to be called from within another subroutine; it is the content of @_ that matters, as demonstrated by the following code.

    $ perl -Mstrict -Mwarnings -E ' @_ = @ARGV; ∑ sub sum { my $sum; $sum += $_ for @_; say $sum; }' 1 2 3 4 5 15 $

    I hope this is of interest.

    Cheers,

    JohnGG