Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl get list of desired parameters

Tags:

perl

Is there a convention to request a list of required parameters for a function? I'd like to be able to call a subroutine which would tell me that I need to provide $phrase and $times when calling @repeat.

use strict;
use warnings;

sub repeat {
    my $phrase = shift;
    my $times = shift;
    return $phrase x $times;
    }
like image 257
nando Avatar asked Feb 18 '15 19:02

nando


1 Answers

Of course, you can build some control mechanism by yourself, depending your needs. But there are some modules to help you with subroutine signatures. I will offer 3 of them:

  1. signatures , the simplest
  2. Kavorka, with type checking
  3. Method::Signatures for OO methods
like image 88
w.k Avatar answered Oct 10 '22 12:10

w.k