confess("Parameter $n stinks") unless $param[$n] =~ /$goodRule[$n]/;
Untested, and not self-contained.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); }
In reply to Re^2: USAGE OF Prototype
by SuicideJunkie
in thread USAGE OF Prototype
by abubacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |