Solved

Limiting An Array

Posted on 1998-06-10
5
163 Views
Last Modified: 2010-03-05
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
Comment
Question by:refr
  • 3
5 Comments
 
LVL 4

Accepted Solution

by:
martinag earned 70 total points
ID: 1207800
$#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
 

Author Comment

by:refr
ID: 1207801
I Think I Need To ReDo That One.
I Need To Make An Array Using Only The Last 5 Elements Of @a.
0
 

Author Comment

by:refr
ID: 1207802
Adjusted points to 75
0
 
LVL 84

Expert Comment

by:ozo
ID: 1207803
@b=@a[-5..-1];
@b=splice(@a,-5); #if you want to remove those elements from @a

0
 

Author Comment

by:refr
ID: 1207804
Great.
Txs
otto
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now