473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to dynamically initialize an array

35
I would like to have an array, its size will be passed as an argument in runtime. And I want to intialize it. How should I do? Thanks.
Oct 21 '08 #1
2 3456
numberwhun
3,509 Expert Mod 2GB
Ok, so what have you tried thus far to do this? This sounds distinctly like school work. If it is, then you need to know that it is against this sites posting guidelines for you to post your homework and expect an answer.

What you are asking is rather fundamental and a quick Google search will help you do what you are asking. Any good "perl arrays" tutorial should explain these basic concepts.

Regards,

Jeff
Oct 21 '08 #2
KevinADC
4,059 Expert 2GB
I would like to have an array, its size will be passed as an argument in runtime. And I want to intialize it. How should I do? Thanks.
You don't have to allocate memory/buckets to arrays in perl if thats what you are thinking. Perl dynamically adds more buckets as needed and when needed. There might be special reasons to allocate some memory to an array before actually adding data into the array, but I don't know what those reasons might be.
Oct 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: SamMan | last post by:
Is there an easy way to re-initialize an array, other than looping through it's length and setting the values to null, or ""? Would unset() be a wise choice? Thanks again -- SamMan
3
by: kaiwing18 | last post by:
HI I want to add two element in a array. the first one is the key and the second is the value.but I want to add it dynamically. i want to do it like the following code: $arr="";...
4
by: Mark Hannon | last post by:
I am trying to initialize an array only once so it can be seen & used by any functions that need it. As I understand it, if a variable is declared by itself outside of any functions, its scope is...
4
by: Ovid | last post by:
Hi all, I'm having a problem trying to create a 2D array whose dimensions are determined at runtime. Below my signoff is a minimal test case that hopefully demonstrates what I'm trying to do. ...
10
by: junky_fellow | last post by:
What is the correct way of dynamically allocating a 2d array ? I am doing it the following way. Is this correct ? #include <stdlib.h> int main(void) { int (*arr)(3); arr =...
13
by: RCS | last post by:
I have a UI that needs a couple of threads to do some significant processing on a couple of different forms - and while it's at it, update the UI (set textboxes, fill in listviews). I created a...
4
by: pauld | last post by:
$sql= sql query $i=0; while ($a2=mysql_fetch_array($a1)){array_push($temparray,$a2,$a2,$a2,$a2); { I want this array to be the value of an asssoc. array $results $results =$temparray doesnt...
1
verbatim
by: verbatim | last post by:
with the following page, the dynamically generated fields are not recognized when i try to submit the form, or add more elements. when i hit my submit button, the address bar has only x1 - x5 in...
1
by: Richard Harter | last post by:
On Fri, 27 Jun 2008 09:28:56 -0700 (PDT), pereges <Broli00@gmail.comwrote: There are some obvious questions that should be asked, e.g., is the contents of your array already sorted as your...
3
by: sherman | last post by:
string ***dat_array; int t; dat_array = new string **; for (i=0; i<t; i++) { dat_array = new string *; for (j=0; j<5; j++) dat_array = new string ; } // dat_array = new string **;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.