How can I validate function parameters in Perl?

Viewed 1535

Could you please tell me what in Perl is the smartest way to validate function parameter?

Code-Snippet:

sub testfunction {
    my ($args) = @_;
    my $value = $args->{value} || die "no value set";
    # process value ...
}


testfunction({value => 'Hallo'});

testfunction({novalue => 'Hallo'});

Is the above way an good alternative to validate function parameter in perl or are there smarter ways? Many Thanks to everybody.

2 Answers
Related