Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 10-18-2009, 12:08 AM
pfyon's Avatar
pfyon
Discordant
 
Join Date: Mar 2009
Location: Ottawa
Posts: 495
Default

Not a lot of experience with perl either, but you just want to know the length of the array? A quick google got me this blog posting with 3 ways to determine the number of elements in an array: http://www.devdaily.com/blog/post/pe...gth-perl-array .

Code:
A frequently asked question Perl question is "How do I determine the size of a Perl array?", or the equivalent "How do I determine how many elements are in a Perl array?"

There are at least three different ways to do determine the length of a Perl array. The easiest way to demonstrate this is with some sample source code:

#----------------------------#
# create a simple Perl array #
#----------------------------#
@foods = qw(burgers fries shakes);

#------------------------------------------------------#
# three different ways to get the size of a Perl array #
#------------------------------------------------------#

# 1) implicit scalar conversion:
$size1 = @foods;

# 2) explicit scalar conversion:
$size2 = scalar @foods;

# 3) index of the last element in the array, plus one:
$size3 = $#foods + 1;

printf("The sizes are %d, %d, and %d\n", $size1, $size2, $size3);

which has the corresponding output:

The sizes are 3, 3, and 3
Reply With Quote
 


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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 06:31 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3