On Sun, 20 Oct 2002, steve silvers wrote:

> In a nutshell I have a text file with dates in it (01 - 31) that are pipe
> delimited. In one month I might have.
>
> 01|05|10|14|22|30
>
> the next month I might have
>
> 01|10|22|28|31
>
> The lowest number is obviously 01, and can reach 31.
>
> I need to read in the text file, which is done but I need to know which
> dates appear together the most. The above example would produce "01 and 10"
>
> open(FILE,dates.txt) || die "Can't open dates.txt file $!";
>      while <FILE> {
>           print "What dates the tasks are done on the most";
>           print "bla.. bla.. bla..";
>      }
>
>
> How can I read in a few years worth (on the same text file) and find the
> dates that appear the most together.
>

One way is to split the days out and then keep count of each day
using a hash where the day is the key. You can then create an array
of the values of "count:day". Then do an decending arithemetic sort of
those values. That will give the days with the highest count first.


while(<F>) {
  @days=split('|',$_);
  foreach $day (@days) {
     $count{$day}++;
  }
}
#repeat above if you have multiple files, accumulating into the %count hash
foreach $key (keys %count) { #create the 31 element array of days
  push(@info,"$count{key}:$key");
}

#this will sort using only the stuff before the : as the arithmetic value
@info= sort {$b<=>$a} @info;

foreach $day (@info) {
  ($count,$day)=split(':',$day);
  print "day $day: count=$count\n";
}

**** [EMAIL PROTECTED] <Carl Jolley>
**** All opinions are my own and not necessarily those of my employer ****

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to