CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
"population tracking"


New User

Apr 5, 2007, 7:07 PM

Post #1 of 2 (1153 views)
"population tracking" Can't Post

Hey everybody. I'm having some trouble with a concept I'm trying to code. I've got the logic and the basic math behind it, but I have no idea how to start coding it.

So here's what I'm trying to do:

I have a fake "world" that has residents. People can be from age 0 to age 49 before they die at age 50. People can reproduce from age 20-30, and can work from age 10-49.

What I need to figure out is how to go about following the population growth patterns. I have a 3D chart in mind, and I know that I need to track the year, the age, and the pop count.

I'm starting with 2 20-year olds at year 1. So year 2 would be 2 21-year olds, year 3 would be 2 22-year olds, etc...

I don't know how to represent this via a script. My first thought is to create an array that has 50 elements (1 per age) and assign the 19th element a value of 2 (to represent the 2 20ys).

But how would I go about shifting the pop for each age every year? If I do an iteration for every element in the array, that's 50 * 100 years, so 5000 total which seems like I'm not doing something right.

Is there a way to shift array elements in the way I'm thinking? Or is the array approach just wrong all together?


Apr 6, 2007, 9:47 AM

Post #2 of 2 (1145 views)
Re: [FoohonPie] "population tracking" [In reply to] Can't Post

You probably want to use a hash if this all going to be done using perl data types.

%people = ( 
dave => {
age => 1,
sex => 'M',
occupation => 'Doctor',
etc => etc,
etc => etc,
jane=> {
age => 1,
sex => 'F',
occupation => 'CEO',
etc => etc,
etc => etc,

the first three tutorials at the link below discuss working with complex perl data:
but there are many many ways you could go about structuring your data.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives