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.

In reply to Re: Re: validating function input by adamk
in thread validating function input by bobdeath

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.