Solved

Limiting An Array

Posted on 1998-06-10
5
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Any syntax error for this clone.plscript 6 148
XPath Syntax help in conjunction with perl XML::LibXML 18 141
Perl Versus AWK? 7 94
octal error in perl program 3 40
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

739 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