#!/usr/bin/perl ##################################################### #first scan the input file and compute the top language for each location... open(FILE, "./gkg2all_roundedtwodec.csv"); while() { ($lat, $long, $lang, $cnt) = split/,/, $_; $cnt=~s/\s+$//; if ($lang eq '') { $lang = 'eng'; } if ($cnt > 0) { $LANGBYCELL{"$lat,$long"}{$lang} = $cnt; } } close(FILE); ##################################################### open(OUT, ">./LOCSBYLANGS.TXT"); foreach $cell (keys %LANGBYCELL) { ($lat, $long) = split/,/, $cell; @arr = (sort {$LANGBYCELLL{$b} <=> $LANGBYCELL{$a}} keys %{$LANGBYCELL{$cell}}); print OUT "$lat,$long,$cnt,$arr[0]\n"; } close(OUT); #####################################################