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

The call

&DISP_HTML(&POPULATE_TEMPLATE(&READ_RECORD("/var/www-ssl/html/dartcart +/o_summary.html"),\%in))

The Sub line 409

sub POPULATE_TEMPLATE($%;$) { # Arguments: <'template_string'> <Hash_ref> <'option word'> # Prototype: scalar, hash ref., scalar # Return: scalar # Reads a formated template string. # This string should contain hash key names bracketed by percent s +igns (e.g. %name% ). # Associated values in the referenced hash are substituted 'in-pla +ce'. # # The 'option word' = raw disables the tag cleanup. Used in debug +ging. my ($first, $last, $template_string, @message_block, %internal); $template_string = $_[0] %internal = %{$_[1]}; ...

The Warning root@ubuntu11:/usr/lib/cgi-bin# Fri Apr 6 15:42:42 2012 quick8.cgi: Prototype after '%'for main::POPULATE_TEMPLATE : $%;$ at quick8.cgi line 409.
The sub POPULATE_TEMPLATE ($%;$) worked for Perl 5.6., 5.8, and in 5.10? and fails Perl 5.12.4.
Any Ideas? Cant seem to find any references prototype usage this manor and the updated syntax. My Perl programmer has moved on.

Replies are listed 'Best First'.
Re: sub Prototype Syntax
by eyepopslikeamosquito (Archbishop) on Apr 07, 2012 at 04:59 UTC

    First, the code you posted has a syntax error in that you are missing a semi-colon after the first line below:

    $template_string = $_[0] %internal = %{$_[1]};
    There are also some stylistic oddities, such as using ALL CAPS for function names, calling the function with a leading &, and using prototypes (see next para), that caused me to pull a face -- though not errors they show dubious style IMHO.

    Second, you probably shouldn't be using prototypes at all. For why not see:

    This new 5.12 warning that you experienced is described in perl 5.12 perldelta (search for "prototype after"). It seems you can silence this warning by adding the line:

    no warnings 'illegalproto';
    after your "use warnings" line (I am assuming you are using strict and warnings). However, I doubt that blindly silencing this warning is a good idea because it is telling you that the prototype is invalid -- presumably because of the optional arguments after the '%' character (I don't use prototypes so I'm not certain of that). See perlsub for Perl prototype documentation. You can also make it go away by simply removing the prototype (recommended) or shortening it to just:
    sub POPULATE_TEMPLATE($%) {

Re: sub Prototype Syntax
by chromatic (Archbishop) on Apr 07, 2012 at 04:56 UTC

    I think 5.12 added a warning about the unbackslashed @ and % prototypes eating up the rest of the arguments, but the bug is in the code you posted.

    The solution (as usual) is to avoid the use of prototypes. They don't do anything for you in this case. You're fine using:

    sub POPULATE_TEMPLATE { ... }

    ... and you might as well get rid of the leading ampersand on the function calls (which bypass prototypes anyhow):

    DISP_HTML( POPULATE_TEMPLATE( READ_RECORD("/var/www-ssl/html/dartcart/o_summary.html"), \%in))

    Improve your skills with Modern Perl: the free book.

Re: sub Prototype Syntax
by ikegami (Patriarch) on Apr 07, 2012 at 05:15 UTC

    "@" and "%" mean the same thing: an arbitrary lengthy list of arguments. As such, they gobble the remainder of the arguments, and "$%;$" is therefore the same thing as "$%". That means you have code which never does anything, so Perl warns you.

    Secondly, "%" doesn't mean "hash ref". A hash ref is simply a scalar, so that would be "$", for a complete prototype of "$$;$".

    You never noticed either error because you explicitly ask Perl to ignore the prototype by using "&" in front of your sub call. Why do you bother creating prototypes if you're just going to ask Perl to ignore them?

    None of this is new to 5.12. Apparently, you just weren't warned about your error before then.