[SOLVED] How to restrict the perl array maximum size?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I get it. But depending of what you want to do you can proceed differently.
For info you can't predefine the max numb of element that your array will hold.
but what you can do for example is checking how many element your array have before adding it a new element:
Ex:
Code:
if ($#myArray > 6) {
print "we can't add this value to this array.";
}
else {
push(@myArray, "My new value");
}
Does this can fit your need?
if not please explain in more detail the context where you want to implement this.
Actually, I am expecting a predefined function to serve this purpose like if am trying to access an array element which will reside beyod my limit I should be warned.
Anyway,Thanks for your reply.
Happy Posting... Bye.....
Actually, I am expecting a predefined function to serve this purpose like if am trying to access an array element which will reside beyod my limit I should be warned.
Anyway,Thanks for your reply.
Happy Posting... Bye.....
Perl's arrays are deliberately without limits of this kind. In most cases, it makes them much easier to work with.
So, I don't know of a predefined function that will work the way you want - at least, not one predefined by Perl itself. However, you can always create your own function if you like and set whatever limits you want there.
Let me ask a different question though: why do you think you need this? What sorts of cases are you worried about, or what problems are you running into? I suspect you think you need a limitation that you don't really need.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.