in reply to What is $#_ ?

This variable returns the number of array elements in @_ - For example:

#!/usr/bin/perl -Tw use strict; my @array = (1..5); # Pass @array to the &count subroutine and print returned result # print "There are ", &count(@array), " elements in \@array.\n"; sub count { # The arguments are passed to &count and are in @_ # return $#_ + 1; };

 

Ooohhh, Rob no beer function well without!

Replies are listed 'Best First'.
Re: Re: What is $#_ ?
by davorg (Chancellor) on Nov 16, 2001 at 14:07 UTC
    This variable returns the number of array elements in @_

    <pedant>
    Not exactly. $#_ contains the index of the last element in @_. This is actually one less than the number of elements in @_ (assuming that you haven't messed with the value of $[ - which you should never do[1]).
    </pedant>

    [1] In fact, please forget[2] I ever mentioned that you can.
    [2] Please look into the red light *FLASH*

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."