in reply to Re^2: Perl Module
in thread Perl Module

Perl prototyping does not care about the type of the arguments

Not true:
#!/usr/bin/perl use strict; use warnings; sub mysub (\@) { my $arg = $_; print ref $arg."\n"; } my (@array, %hash, $scalar); mysub (\@array); mysub (\%hash); mysub (\$scalar); mysub (@array); # This is the only one which compiles mysub (%hash); mysub ($scalar); mysub (qw(This is a list));
Gives (5.10):
Type of arg 1 to main::mysub must be array (not reference constructor) + at C:\gash.pl line 15, near "@array)" Type of arg 1 to main::mysub must be array (not reference constructor) + at C:\gash.pl line 16, near "%hash)" Type of arg 1 to main::mysub must be array (not single ref constructor +) at C:\gash.pl line 17, near "$scalar)" Type of arg 1 to main::mysub must be array (not private hash) at C:\ga +sh.pl line 20, near "%hash)" Type of arg 1 to main::mysub must be array (not private variable) at C +:\gash.pl line 21, near "$scalar)" Type of arg 1 to main::mysub must be array (not list) at C:\gash.pl li +ne 23, near "qw(This is a list))" Execution of C:\gash.pl aborted due to compilation errors.

Replies are listed 'Best First'.
Re^4: Perl Module
by CountZero (Bishop) on Jan 01, 2009 at 22:08 UTC
    You are right, I should have said "Perl prototyping does not always care about the type of the arguments". And that is arguably even worse.

    In any case, it only happens when you do "reference prototyping" and the OP did not ask about that dark corner.

    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