C is a typed language, Perl is a dynamic language. I know it is a natural thing to do, but it is dangerous to take a feature of one and try and appy it to another.
Consider it this way. Start with: all Perl subroutines are variadic with no fixed arguments or return type. In C we have variadic functions with a prototype like this:
type myfunc (type arg,...)
The return type is fixed, but a feature of Perl is that the return type is not fixed - it can be a single value or a collection of values, and that can be a mixture of anything you like. There are no constraints.
In C the type of the first argument is fixed, then
all following argument types are determined at runtime. Think what happens in C when you say this:
int i = 42;
printf ("%s\n",i);
More than likely printf will crash with exception C0000005 on Windows or SIGSEGV on UNIX/Linux. In Perl it won't crash, it will print "42" - it is dynamic.
Yes there are "prototypes" in Perl, but, as
moritz said, they are not the same as those in C, they force context not type. You could ask "how do I change a variable's context in C"? It is a daft question, because C does not have context.
Update: some rewording for clarity.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.