package V; use Carp; sub is_array_of_scalar { my $arg = shift; if (!defined $arg) { warn "Undefined value! Expected reference to an array of scala +rs!"; return 0 } if(ref $arg ne "ARRAY") { warn "Expected ARRAY reference, found " . ref($arg) . "."; return 0; } for my $index(0..$#$arg) { if(!defined($arg[$index])) { warn "Undefined value found on position $index."; return 0 } if(ref($arg[$index]) ne "") { warn "Scalar expected, reference found on position $index. +"; # (1) return 0 } } return 1; } sub is_array_of_array_of_scalar { my $arg = shift; if (!defined $arg) { warn "Undefined value! Expected reference to an array of scala +rs!"; return 0 } if(ref $arg ne "ARRAY") { warn "Expected ARRAY reference, found " . ref($arg) . "."; return 0; } for my $index(0..$#$arg) { if(!is_array_of_scalar($arg[$index])) { warn "Wrong value(s) in row $index."; return 0 } } return 1; } "true value at the very end";
And here is the problem: Is it possible to say precisely, i.e. that some wrong value is in row 5, column 3? Above code won't do it. Function is_array_of_scalar doesn't know, which column it is checking. Is the Sub::Contract module proper to perform such checks or rather to do simpler (and not nested) ones only?
Update: $_ corrected in loop, thanks JadeNB
In reply to proper Sub::Contract use by grizzley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |