Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Length of Array 1

Status
Not open for further replies.

audiopro

Programmer
Joined
Apr 1, 2004
Messages
3,165
Location
GB
I have the following code which works ok but the lengths of the arrays vary. I need to get the length ($LENF) of the actual array based on the reference name if possible.
Code:
$WHICH_TABLE=1;
$LENF=31;
my @SOURCE_TEXT= (\@DUMMY, \@PTEXT, \@CTEXT, \@BTEXT);
for($x=0; $x<$LENF; ++$x){
	print "$x - $SOURCE_TEXT[$WHICH_TABLE][$x]<br>";
}


Keith
 
Using an array in scalar context will cause it to return its length. To get the length of @SOURCE_TEXT:
Code:
$LENF = @SOURCE_TEXT;
 
Thanks but @SOURCE_TEXT is an array of references.
I need to get the length of the arrays which the @SOURCE_TEXT is a reference to.

Keith
 
OK - to get the length of the first array in @SOURCE_TEXT:
Code:
$LENF = @{ $SOURCE_TEXT[ 0 ] );
 
Thanks ishnid, I knew there would be a way but I would never have guessed it.
Worth mentioning the typo at the end for anyone using this thread as a reference. The final bracket should be curly.

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top