in reply to Re: Read all the file path having text document
in thread Read all the file path having text document

I agree that prototyping is unnecessary and potentially very confusing in the OPed code (and in general) and should be avoided, but in the specific code given in the OP, isn't predeclaration of the subroutine necessary – at least to avoid a warning?
>perl -wMstrict -le "sub S ($); S('foo'); sub S ($) { print $_[0], '-totyped subroutine' }; " foo-totyped subroutine >perl -wMstrict -le " S('foo'); sub S ($) { print $_[0], '-totyped subroutine' }; " main::S() called too early to check prototype at -e line 1. foo-totyped subroutine

Replies are listed 'Best First'.
Re^3: Read all the file path having text document
by GrandFather (Saint) on Nov 29, 2008 at 23:33 UTC

    No prototype, no warning.


    Perl's payment curve coincides with its learning curve.
      No prototype, no warning.
      Did you mean to convey that simply omitting the prototype from the predeclaration would suppress the warning?
      >perl -wMstrict -le "sub S; S('foo'); sub S ($) { print $_[0], '-totyped subroutine' }; " foo-totyped subroutine
      I was rather surprised to find that this worked! Can you point me to an explanation of why this works as it does?

      In any event, I continue to agree it is best to avoid prototyping both in the OPed code and in general.

        Actually, I'm surprised too. I really meant omit the prototype specification on the sub declaration:

        sub S {...}

        rather than:

        sub S ($) {...}

        In other words, don't use the prototype at all is the fix rather than using a forward declaration. If the sub isn't prototyped the forward declaration isn't required.

        A forward declaration with a different prototype than the actual declaration is an error reported by Perl, but not if the forward declaration is missing the prototype and the declaration has one - bizarre.


        Perl's payment curve coincides with its learning curve.