Here is some simple code for you to play with:

A Perl prototype is only marginally useful.
There is no "type checking".

One thing that a prototype can do is to allow you to call a user sub without () around the args...sort of mimicking a Perl built in function. I personally think this is a bad idea and use of prototype. I always enclose args in () for my functions.

Play with the below code which just shows a simple scenario with $ representing a scalar value.

#!/usr/bin/perl -w use strict; some_sub(1,2); #called too early warning error #but note that the code still runs! sub some_sub($$) #this sub requires 2 scalars { my ($a,$b) = @_; print "$a,$b\n"; } some_sub 6,8; #ok,now this is just fine some_sub 10,11,12; #too many argument error __END__ main::some_sub() called too early to check prototype at C:\TEMP\perl33 +.pl line 6. 1,2 if you reverse order or add proto above call: sub some_sub($$); some_sub(1,2); sub some_sub($$) { my ($a,$b) = @_; print "$a,$b\n"; } Perl will be happy, but to what effect?

In reply to Re: subroutine prototype in Perl by Marshall
in thread subroutine prototype in Perl by pavunkumar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.