Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

Limiting An Array

How Can I Limit An Array To The First 5 Elements?
Make This Array: @a(1,2,3,4,5,6,7)
This Array @a(1,2,3,4,5)
0
refr
Asked:
refr
  • 3
1 Solution
 
martinagCommented:
$#a = 4; # gives it the length 5

You have to shorten the array as fast as you make it longer than 5:
@a = (1,2,3,4,5,6,7);
$#a = 4; # @a = (1,2,3,4,5)

@a = (1, 2, 3, 4, 5, 6, 7); # Now are there 7 elements again.
0
 
refrAuthor Commented:
I Think I Need To ReDo That One.
I Need To Make An Array Using Only The Last 5 Elements Of @a.
0
 
refrAuthor Commented:
Adjusted points to 75
0
 
ozoCommented:
@b=@a[-5..-1];
@b=splice(@a,-5); #if you want to remove those elements from @a

0
 
refrAuthor Commented:
Great.
Txs
otto
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now