You seem to have an answer to your question, but moving forward, there are some things to keep in mind with prototypes, namely that: Perl prototypes are a guide to the compiler, not a list of expected types (as in Java and other languages).

In general you should stay away from them unless

All other uses are likely not a good idea. For example, you can use prototypes to force the compiler to fail unless a certain general category of variable is passed. However, to do that, you will have to go against normal ideas of how parameters are used. If you do use prototypes for this purpose, document it very carefully. Even then people are likely to mess things up.

Suppose, for example, you are defining a function (not method) and you have a specific reason for insuring that the parameter being passed is an lvalue (i.e. something to which a value can be assigned, like a variable). If function foo is defined sub foo(\$) then the call foo(1) will fail to compile with the complaint: "Type of arg 1 to main::foo must be scalar (not constant item)". Only calls like foo($x) will be accepted by the compiler.

However, the normal Perl convention is to copy parameters to named variables, so users reading the calling code may not be expecting that foo($x) is actually passing \$a (a reference to $a) and is going to change the value of $x in some way. If you had forgone the prototype and passed foo(\$x) instead, readers seeing the function call would know that something might be happening to the value of $x and would take special care.

Best, beth


In reply to Re: How can I use the values which is passed as arguments? by ELISHEVA
in thread How can I use the values which is passed as arguments? by anbutechie

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.