in reply to Re: validating function input
in thread validating function input

I should mention there is a variety of different uses for this as well.

The most common are:

sub foo { my $self = shift; # Is there a variable at all ( even undef ) my $anything = @_ ? shift : return undef; # Is there a defined argument my $def = defined $_[0] ? shift : return undef; # Is there a true argument my $true = $_[0] ? shift : return undef; # Is there an argument which conforms to a regex? my $re_ok = $_[0] =~ /^\w+$/ ? shift : return undef; # If the argument one of a limited number of values my $option = $_[0] =~ /^(?:this|that|foo|bar)$/ ? shift : return u +ndef; # Is it a reference my $ref = ref $_[0] ? shift : return undef;
You get my point... it can be extended to cover most of the basics pretty well, and it probably much faster than calling to another subroutine.