Gil Magno wrote:
On 19/11/17 13:57, hw wrote:
without being able to use feature 'signatures', how do I verify
that parameters passed to a function have been passed to it by
the caller?

If you're dealing with positional parameters[1] (and not with named
ones) you can check for the size of @_ inside your function, that is,
you can check for the quantity of parameters given by the caller.

    sub one {
        $num_of_params = scalar @_;
        print "$num_of_params\n";
    }

    one('str1'); # prints '1'; there's just one parameter

    one('str2', undef); # prints '2'; the second parameter is undef,
                        # but the undef counts and it prints '2'

[1] Positional parameters would be as in sub_one('John', 'Zimbabwe');
and named parameters as in sub_two({ name => 'John', country =>
'Zimbabwe' });


I´m dealing with both types.

I shouldn´t even need to explicitly verify if positional arguments
required by a function have been supplied to it.  It´s enough having to
verify that the values which were supplied via such arguments are ok, and
verifying the arguments themselves means having to add basically obsolete
code.

Isn´t there some sort of perl interpreter/compiler/module which can verify
the passing of arguments automatically at least when running the program in
some sort of debugging mode?

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to