CGI/Perl Guide | Learning Center | Forums | Advertise | Login Site Search: in Perl Guide PerlGuru Forums Learning Ctr
 MAIN INDEX SEARCHPOSTS WHO'S ONLINE LOG IN

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

FoohonPie
New User

Apr 5, 2007, 7:07 PM

Post #1 of 2 (1149 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?

KevinR
Veteran

Apr 6, 2007, 9:47 AM

Post #2 of 2 (1141 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.

 Code
`%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.
-------------------------------------------------

 Announcements     PerlGuru Announcements Perl Programming Help     Frequently Asked Questions     Beginner     Intermediate     Advanced     Regular Expressions     mod_perl     DBI     Win32 Programming Help Fun With Perl     Perl Quizzes - Learn Perl the Fun Way     Perl Golf     Perl Poetry Need a Custom or Prewritten Perl Program?     I need a program that...     I Need a Programmer for Freelance Work     Throw Down The Gauntlet General Discussions     General Questions     Feedback     Tutorial/Article Suggestions for The Learning Cent     Internet Security Other Programming Languages     Javascript     PHP

 Search this forum this category all forums for All words Any words Whole Phrase (options) Powered by Gossamer Forum v.1.2.0