in reply to Perl newbie question.

You could try to split your parameter and access the number of elements ... something like this:

my @nr = split (/\s+/, $_[0]); print ($#nr+1, " params \n");

However you might want to do some fine-tuning ... the code above won't work correctly for parameters starting with whitespaces

HTH, Rata

update: or as an one-liner: print (scalar(split (/\s+/, $_[0])), " params \n");

Replies are listed 'Best First'.
Re^2: Perl newbie question.
by kiruthika.bkite (Scribe) on Mar 19, 2010 at 09:24 UTC
    my $nr = split (/\s+/, $_[0]);

    We can get the number of elements by simply assigning the return value of split into a scalar variable.

    Example
    $str="1:3:4:5"; my $num=split(':',$str); print "Num:$num";

    $num will contain '4'.