"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
o
> -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
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
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
For a normal array (@MyArray), one can use $#MyArray to get the position of
the last element.
So, if I'm given $MyArrayRef, how does one do the same operation to find out
how many things are in MyArrayRef?
Ex:
sub MySub
{
my ($aref)=@_;
return(__);
}
my @MyArray = (0,