in reply to Detecting undefined subroutines at compile time

Perl detects undeclared subs (which is better than detecting undefined subs) at compile-time if you omit parens on sub calls.

>perl -c -e"use strict; sub f {} f;" -e syntax OK >perl -c -e"use strict; sub f; f;" -e syntax OK >perl -c -e"use strict; f;" Bareword "f" not allowed while "strict subs" in use at -e line 1. -e had compilation errors. >perl -c -e"use strict; sub g {} g 'abc';" -e syntax OK >perl -c -e"use strict; g 'abc';" String found where operator expected at -e line 1, near "g 'abc'" (Do you need to predeclare g?) syntax error at -e line 1, near "g 'abc'" -e had compilation errors.

Omitting parens on sub calls causes a whole of weird stuff, so I recommend against doing this.

Replies are listed 'Best First'.
Re^2: Detecting undefined subroutines at compile time
by Anonymous Monk on May 04, 2011 at 17:07 UTC
    Omitting parens on sub calls causes a whole of of weird stuff,

    The hard evidence in your post completely contradicts your premature summation.

    I see clear, consise error messages.

      Evidence that it does work at finding undeclared functions does not contradict the claim that omitting parens in function calls introduces problems.

      The main problem is that unary "+" or equivalent must be used in a number of places, and forgetting to do causes bugs. These are not always caught at compile-time, and they can be subtle.

      Another problem is misleading error messages.

      Three issues from omitted parens came up here and/or on stack-overflow in the last month, but I don't remember them.