> -----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 element.
> 
> So, if I'm given $MyArrayRef, how does one do the same 
> operation to find out
> how many things are in MyArrayRef?

$len = @$MyArrayRef;            # length of array (scalar context)
$end = $#$MyArrayRef;   # index of last element

> 
> Ex:
> 
> sub MySub
> {
>       my      ($aref)=@_;
> 
>       return(______);

return scalar @$aref;   # to return length of array
return $#$aref;         # to return index of last element

> }
> 
> my @MyArray = (0, 3, 6, 9, 154);
> 
> my $LastElement=&MySub(\@MyArray);
> 
> print "The last element is: $LastElement\n";
> 
> 
> 
> What goes in ___________?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to