thekestrel has asked for the wisdom of the Perl Monks concerning the following question:
I know this is a little generic, but lets say most subroutines can take a generic number style argument and others take a generic string type argument I want to make sure thats all they are.sub Func1 { do we have a num_var; do we have a name_var; do we have params (optional) is the num_var of number format is the name_var of name format .... other code } Func1($num_var, $name_var, %params);
or are there more elegant solutions that are generally used...something like?Func1 { is number of args correct? check arg1 is a number and only a number with reg exp? check arg2 is a string and only a string with reg exp? ... other code }
sub CheckArgs { get number of args get args to check check we have the right number of args foreach arg check the type with the appropriate reg exp. return status. } sub Func1 { CheckArgs (2, @_, "NUM", "STRING"); .... other code } sub Func2 { CheckArgs (3, @_, "STRING", "NUM", "STRING"); .... other code }
sub add_output { #Create an unconnected named output my $self = shift; my $graph = $self->{graph}; my $name = shift; my %params = @_; #Check for valid options foreach my $p ( keys %params ) { if ( !exists $valid_userconfigurable_vertex_params->{$p} ) { Carp::confess(sprintf "Unknown Option : $p"); } } #Set the activation function my $activation; if ( exists $params{activation} ) { $activation = $params{activation}; } else { $activation = "SIGMOID"; } #Create the vertex $graph->set_vertex_attributes($name, { id => GetNewVertexNumb +er($self), added_a_vertex => 1, allow_inputs => "Yes", allow_outputs => "No", activation => $activat +ion, value => 0 }); #Connect vertex to the bias vertex $graph->add_edge("BIAS", $name); #An update to the layout is required $graph->set_graph_attribute("update_layout", 1); }
2005-03-30 Janitored by Arunbear - added readmore tags, as per Monastery guidelines
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing Edges
by dragonchild (Archbishop) on Mar 29, 2005 at 18:25 UTC | |
by thekestrel (Friar) on Mar 29, 2005 at 20:29 UTC | |
by thekestrel (Friar) on Mar 29, 2005 at 23:15 UTC | |
by cberg (Scribe) on Mar 30, 2005 at 09:04 UTC | |
|
Re: Testing Edges
by Tanktalus (Canon) on Mar 29, 2005 at 18:00 UTC | |
|
Re: Testing Edges
by ikegami (Patriarch) on Mar 29, 2005 at 17:44 UTC |