in reply to Re: Perl Module
in thread Perl Module
One thing they DO NOT do is compile-time (or even run-time) checking of the arguments in the argument-list.
Consider the following:
In some way (but not in others) one can say that the $ prototype magically causes the argument to the sub to be evaluated in scalar context. This all happens silently without any warning or error to the user. Saying (as perlsub does) "Perl supports a very limited kind of compile-time argument checking using function prototyping." is misleading to the unwary.sub test_noproto {print shift;}; sub test_proto ($) {print shift;}; $scalar = 'A'; @array = qw /X Y Z/; %hash = ('key', 'value'); test_noproto($scalar); # gives as expected: A test_noproto(@array); # gives as expected: X test_noproto(%hash); # gives as expected: key test_proto($scalar); # gives as expected: A test_proto(@array); # gives: 3 Did you expect that? test_proto(%hash); # gives: 1/8 Did you expect that?
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl Module
by spx2 (Deacon) on Dec 31, 2008 at 06:54 UTC | |
by CountZero (Bishop) on Dec 31, 2008 at 07:16 UTC | |
by tilly (Archbishop) on Dec 31, 2008 at 07:53 UTC | |
by cdarke (Prior) on Dec 31, 2008 at 15:24 UTC | |
by shmem (Chancellor) on Feb 19, 2010 at 15:50 UTC | |
by CountZero (Bishop) on Feb 19, 2010 at 19:34 UTC |