Number of arguments to array - Perl Script

I have the following proc.

proc get_add {arg1 arg2 arg3 arg4 arg 5 .. ... arg N }
{
}

i need to count the number of arguments and also i need those arguments stored in an array.
please help out

---------- Post updated at 06:33 PM ---------- Previous update was at 05:30 PM ----------

can i do it using pattern matching. pls help

If this is in a Perl script you may need to fix a couple of things, I suspect you mean the get_add routine to look like

sub get_add{
    my @args=@_;
    my $num_args=@args;
    my$last_index=$#args;
    ...
    return $some_value;
}
...
get_add(arg1,arg2,arg3,arg4,arg5, ... ,argN);

Prototypes in Perl are not for the uninitiated, a subroutine is defined with the sub keyword, work around the snippet above and see if it's what you need.

---------- Post updated at 01:25 PM ---------- Previous update was at 01:13 PM ----------

When you call a routine with a list of arguments, you are passing an array to the routine in the special array @_ .

In order to determine the number of arguments using a regular expression, you would first have to join them with a sufficiently unique key and then parse them out with the regex, this seems...strange.

Could you specify your problem more clearly, or if it is coursework, move the conversation to that forum filling all the required fields.

Regards, Skrynesaver

1 Like