Skip to content

Home > GNU/Linux > A small annoying bug in my perl code ...

A small annoying bug in my perl code ...

Just in that that happens ... again

Thursday 9 January 2014, by Stéphane Téletchéa

Here is the offending code:

sub blah(){
    my ($string)=$_0;
    open(LOGFILE,">the_file.log") or die "Unable to open the logging file: $!\n";
    print LOGFILE "$string\n";
    close(LOGFILE);
}

This routine is a simple code to log a varying message into a logging file...

While calling this routine :

blah("This does not work here!");

I get the error message:

Too many arguments for blah at ...

And this reason is explaned here http://stackoverflow.com/questions/11929415/too-many-arguments-when-passing-an-array-to-perl-sub.

The rationale behind this is if you add parenthesis inside your function definition, then this indicates that this function does not accept arguments...

Solution : remove the parenthesis, or use a proper prototype to the function.

Comment on this article