in reply to sub execution order aka missing semicolon after sub call

That's because without the semicolon, Perl understands the code as

sub_A(sub_B());

as you can easily verify with B::Deparse:

$ perl -MO=Deparse,-p ~/1.pl sub sub_A { use warnings; use strict; print("sub_A\n"); } sub sub_B { use warnings; use strict; print("sub_B\n"); } use warnings; use strict; sub_A(sub_B());

My advice is you should get into the habit of always using parentheses for function calls.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: sub execution order aka missing semicolon after sub call
by jmaas (Initiate) on Apr 06, 2016 at 15:41 UTC

    Thanks to all repliers.

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

      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