Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all.

I am getting the error below when trying to run my file.

...Prototype mismatch: sub main::trim: none vs ($) at ...

I am not using LPW as this seems to be the cause for others.

Any other ideas of what may be the cause?

Thanks in advance.

Replies are listed 'Best First'.
Re: Prototype mismatch: sub main::trim: none vs ($) at
by davido (Cardinal) on Mar 04, 2011 at 09:09 UTC

    The part after "at" probably lists a line number from your code, or from the module you're using. But you showed no code in your post. I think we're going to need more information than you've provided if we are to help you with this issue. Please post a minimally constructed executable snippet of code that replicates your error.

    Do you mean LWP, instead of LPW? I did a search for LPW and Perl, and came up with the same blank that my mind produced when I read your question.


    Dave

      Googling for the error message returns matches mentioning LWP.
Re: Prototype mismatch: sub main::trim: none vs ($) at
by Anonymous Monk on Mar 04, 2011 at 09:10 UTC
    Any other ideas of what may be the cause?

    Exactly what the message says, a prototype mismatch

    $ perl -Mdiagnostics -e " sub trim(); sub trim($){warn@_} ; " Prototype mismatch: sub main::trim () vs ($) at -e line 1 (#1) (S prototype) The subroutine being declared or defined had previou +sly been declared or defined with a different function prototype.
Re: Prototype mismatch: sub main::trim: none vs ($) at
by ikegami (Patriarch) on Mar 04, 2011 at 17:25 UTC

    There are three related problems:

    • An explicit declaration of a function and its definition don't match:

      >perl -we"sub trim(@); sub trim($) {}" Prototype mismatch: sub main::trim (@) vs ($) at -e line 1.

      There's no problem if the declaration has no prototype, so this isn't the cause of your problem.

    • An implicit declaration of a function and its definition don't match:

      >perl -we"trim('abc'); sub trim($) {}" main::trim() called too early to check prototype at -e line 1.
    • A function's is defined twice with different prototypes:

      >perl -we"sub trim {} sub trim($) {}" Prototype mismatch: sub main::trim: none vs ($) at -e line 1. Subroutine trim redefined at -e line 1.

      If so, you'll also get a "Subroutine trim redefined" warning. (You do have warnings turned on, right?)

    The last problem is the only one I can get to result in "none vs ($)". The solution, of course, is to get rid of the trim you don't want. Note that you might be importing one (or both) from a module.