in reply to Re: USAGE OF Prototype
in thread USAGE OF Prototype

How would you go about inspecting the contents of a scalar to decide if it is a number using only prototypes?
That sounds like more of a job for:
confess("Parameter $n stinks") unless $param[$n] =~ /$goodRule[$n]/;

Append:
Example of extensive parameter handling:
sub buyWidgets { my $numWidgets = shift; my $supplier = shift; #validate parameters unless ($numWidgets =~ /^\d+$/) { carp("'$numWidgets' is not a valid number of widgets: purchase + canceled\n"; return undef; } # Validate, and be flexible if possible. Accept both "ACME" and +"hash(0xPtrToACME)", and even ["ACME", "Bob's Widgets", "Black Market +"] if (ref($supplier) eq 'ARRAY') { my $buyCount = 0; foreach (@$supplier) { my $result = buyWidgets($numWidgets-$buyCount, $_); $buyCount += $result if defined($result); } return $buyCount; } if (ref($supplier) ne 'Supplier') { unless (exists $globalSupplierDirectory->{$supplier}) { carp("Cannot buy from '$supplier': not a valid supplier\n" +); return undef; } $supplier = $globalSupplierDirectory->{$supplier}; } # Do stuff with the good parameters return $supplier->buyWidgets($numWidgets); }
Untested, and not self-contained.