Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 25th, 2001, 05:16 AM
Flink Flink is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Location: Manchester, UK
Posts: 47 Flink User rank is Private First Class (20 - 50 Reputation Level)Flink User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 h 48 m 9 sec
Reputation Power: 8
array length

Might seem a bit basic, but how do you get the length of an array, in order to make the length of it equal to a given variable?

Cheers.
Flink.

Reply With Quote
  #2  
Old June 25th, 2001, 06:43 AM
startrader startrader is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Posts: 0 startrader User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
$#arrayname

Reply With Quote
  #3  
Old June 25th, 2001, 09:13 AM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ummm

Ok, $#Arrayname will give you the length of the array... but it gives it as the literal highest number you have established in it... which isn't very helpful if you have an array with only one entry.

to get the real number of entrys for an array... use scalar(@ARRAYNAME)

Reply With Quote
  #4  
Old June 26th, 2001, 03:32 PM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
$#arrayname gives you the subscript of the last element you have in said array, which really translates to length minus one.

As Flame said, you could use:
Code:
$len = scalar(@arrayname);


Or you could use simply:
Code:
$len = @arrayname;


Hope that helps.
__________________
- dsb -
Perl Guy

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > array length


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT