What's strategy to write this simple prog. in perl ?

I have a file which contain lots of numbers. I want to find the frequancy of each range.Can somebody
help me with the strategy to write this program. -the file contain numbers say 1-1000 so the min and max are known in advance
-the user input the width eg. 10 so there should be 1000/10 =100 number of classes (width=user input variable)
the program should search and find the frequency between numbers b/w 0-199, 200-299, 300-399 until 1000 so the result should be
class Lower limit upper limit frequency Prop
0 0.000 199.000 120 0.0987

The count of the number of items held in a particular bucket, if that bucket number is n, is in $Buckets{n}->{count}

All the code is doing is running through the file, one line at a time. It reads the number from the file, and

1.) increments the counter for the appropriate bucket.
2.) updates the high or low values, as appropriate.

0

aja101498Author Commented:

Sorry.You know my friend I know very little about Perl that's why I am asking this question so please bear with me. I appreciate your help. Thanks

Frequency:
It is how many number b/w 0.000 and 199.000. Sometimes there are 50 numbers in one range or class and sometimes there are 0 numbers in a class.
Let us say in range or class between 0-199, there are only the following numbers:

20 X the number 0
10 X the number 88
100 X the number 120
1 X the number 7

then
class Lower limit upper limit frequency averagr
0 0.000 199.000 131 131/3

So in other words it is the total number of all the numbers between 0.000 - 199.000

X: times
the first column class is just the serial number of classes. It start from 0 to the 9 if the n=1000 and width=10

OK, so I'm using the word 'count', and you're using the word frequency. (BTW, I've assumed thoughout that your numbers are always positive, i.e. that $Lower is > 0)

Also, it appears that I misunderstood your definitions of upper and lower, and that the min/max code I threw in there is uneccessary.

To figure out the limits, the salient piece of code is the

int($_ - $Lower)/$Width

$_ is the number that was just read, $Lower is your lower bound of all numbers
So your lower limit and upper limit of a basket n would be the smallest and largest numbers, x and y, respectively, for which int(x - $Lower)/$Width = int(y - $Lower)/$Width = n

Thus, the lower limit will be (I don't need to prove I can ignore the int.. trust me, I can :))
n*width + $Lower
and the upper limit will be
(n+1)*width - $Lower - epsilon
(where epsilon is greater than the smallest number on your architecture such that, for any number z, z - epsilon does not equal z.... It looks like you've implicitly used 1.0)

OK, so I'm using the word 'count', and you're using the word frequency. (BTW, I've assumed thoughout that your numbers are always positive, i.e. that $Lower is > 0)

Also, it appears that I misunderstood your definitions of upper and lower, and that the min/max code I threw in there is uneccessary.

To figure out the limits, the salient piece of code is the

int($_ - $Lower)/$Width

$_ is the number that was just read, $Lower is your lower bound of all numbers
So your lower limit and upper limit of a basket n would be the smallest and largest numbers, x and y, respectively, for which int(x - $Lower)/$Width = int(y - $Lower)/$Width = n

Thus, the lower limit will be (I don't need to prove I can ignore the int.. trust me, I can :))
n*width + $Lower
and the upper limit will be
(n+1)*width - $Lower - epsilon
(where epsilon is greater than the smallest number on your architecture such that, for any number z, z - epsilon does not equal z.... It looks like you've implicitly used 1.0)

0

aja101498Author Commented:

If I understood you well the program should work as it is.
but the count variable doesn't have a $ in it as all perl variable so how to print it ?

What to print to get the follwing
class Lower limit upper limit frequency averagr
0 0.000 199.000 131 131/3
1 200.000 299.000 ? ?
2 300.000 399.000 ? ?
and so forth. Thanks