"Tomasi, Chuck" <[EMAIL PROTECTED]> writes:
> For a normal array (@MyArray), one can use $#MyArray to
> get the position of the last element.
"index" is a better term
You usually don't need to use that syntax, however. Use
@MyArray in a scalar context.
$MyLen = @MyArray;
o
$#{ $MyArray } will give you the position of the last element.
-Original Message-
From: Tomasi, Chuck
To: '[EMAIL PROTECTED]'
Sent: 12/20/2001 10:01 AM
Subject: Counting the size of an array reference
For a normal array (@MyArray), one can use $#MyArray to get the position
of
the last e
> -Original Message-
> From: Tomasi, Chuck [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, December 20, 2001 11:02 AM
> To: '[EMAIL PROTECTED]'
> Subject: Counting the size of an array reference
>
>
> For a normal array (@MyArray), one can use $#MyArray to get
> the position of
> the last
Or, better still
sub MySub
{
my ($aref)=@_;
$count = $#{$aref};
return $count;
}
John
-Original Message-
From: Tomasi, Chuck [mailto:[EMAIL PROTECTED]]
Sent: 20 December 2001 16:02
To: '[EMAIL PROTECTED]'
Subject: Counting the size of an array reference
How about
sub MySub
{
my ($aref)=@_;
$count = @{$aref};
return $count - 1;
}
HTH
John
-Original Message-
From: Tomasi, Chuck [mailto:[EMAIL PROTECTED]]
Sent: 20 December 2001 16:02
To: '[EMAIL PROTECTED]'
Subject: Counting the size of an array reference