Thread Codereview Argument Validation (9 answers)
Opened by Kuerbis at 2013-08-26 15:50

Gast wer
 2013-08-27 08:16
#169764 #169764
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env perl
use strict;
use warnings;

sub _validate_arguments {
    my ( $first_arg, $second_arg ) = @_;
    croak "Called without arguments." if @_ < 1;
    croak "Called with " . scalar @_ . " arguments. Expected arguments: 1 or 2." if @_ > 2;
    croak "The first argument is not defined." if ! defined $first_arg;
    ...
    ...
    carp "The first argument refers to an empty list!" if ! @$first_arg;
    return ( $first_arg, $second_arg );
}

sub my_function {
    my ( $first_arg, $second_arg ) = &_validate_arguments;
    return if ! @$first_arg;
    ...
    ...
}


So printet croak das richtige.
Last edited: 2013-08-27 08:38:45 +0200 (CEST)

View full thread Codereview Argument Validation