Nov 30, 2000 #1 rtb1 IS-IT--Management Jul 17, 2000 73 ES Hi, I couldn't find this in the Perl documentation but it must me possible. How can I get the length of an array? $length =@array.length; # returns 00? What is the right syntax? regards, Raoul
Hi, I couldn't find this in the Perl documentation but it must me possible. How can I get the length of an array? $length =@array.length; # returns 00? What is the right syntax? regards, Raoul
Nov 30, 2000 Thread starter #2 rtb1 IS-IT--Management Jul 17, 2000 73 ES sorry, miss typed array name. but apparantly a '0' is added to the actual number. When the length is 5 it returns 50. Is there a reason for this? raoul Upvote 0 Downvote
sorry, miss typed array name. but apparantly a '0' is added to the actual number. When the length is 5 it returns 50. Is there a reason for this? raoul
Nov 30, 2000 #3 goBoating Programmer Feb 8, 2000 1,606 US Try this.... @array = ('1','2','3','4,'5'); $length = $#array; print "$length\n"; # prints 4 which is the fifth element starting with zero. 'hope this helps.... keep the rudder amid ship and beware the odd typo Upvote 0 Downvote
Try this.... @array = ('1','2','3','4,'5'); $length = $#array; print "$length\n"; # prints 4 which is the fifth element starting with zero. 'hope this helps.... keep the rudder amid ship and beware the odd typo
Nov 30, 2000 #4 damann Technical User Jul 19, 2000 114 US simplly doing this is fine: $length = @array; This should work just fine... Upvote 0 Downvote
Nov 30, 2000 #5 goBoating Programmer Feb 8, 2000 1,606 US damann is correct. I was making it harder than it needed to be. Thanks, damann. keep the rudder amid ship and beware the odd typo Upvote 0 Downvote
damann is correct. I was making it harder than it needed to be. Thanks, damann. keep the rudder amid ship and beware the odd typo
Nov 30, 2000 Thread starter #6 rtb1 IS-IT--Management Jul 17, 2000 73 ES Thanks guys, That is even easier than my first thoughts! And it gives the correct number immediately. Upvote 0 Downvote
Thanks guys, That is even easier than my first thoughts! And it gives the correct number immediately.
Dec 4, 2000 #7 Tve Programmer May 22, 2000 166 FR To be sure to get a REAL, you can also use SCALAR, eg: $length = scalar(@array); In an if statement, you could write: if ( scalar(@array) > 1 ) { ....... } Thierry Upvote 0 Downvote
To be sure to get a REAL, you can also use SCALAR, eg: $length = scalar(@array); In an if statement, you could write: if ( scalar(@array) > 1 ) { ....... } Thierry