Why am I getting “called too early to check prototype” warnings in my Perl code?

前端 未结 5 713
你的背包
你的背包 2021-02-07 13:01

I have a Perl file like this:

use strict;
f1();

sub f3()
{ f2(); }

sub f1()
{}
sub f2()
{}

In short, f1 is called before it is d

5条回答
  •  礼貌的吻别
    2021-02-07 13:32

    When you define a function in Perl you should not use parentheses. When you do so you get this error. This is wrong:

    sub DoSomthing(){
       #do what ever...
    }
    

    This is the way to go:

    sub DoSomthing{
       #do what ever...
    }
    

    no parentheses.

    For more detailed explenation see Gabor Szabo's Perl Maven page on Subroutines and functions in Perl. https://perlmaven.com/subroutines-and-functions-in-perl

提交回复
热议问题