| [reply] |
Since $#Array returns the index of the last element of @Array, $#_ returns the index of the last element of @_. @_ contains the arguments made to a subroutine. See perlvar for more info.
Greetz
Beatnik
... Quidquid perl dictum sit, altum viditur. | [reply] [d/l] [select] |
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! | [reply] [d/l] [select] |
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."
| [reply] |