#!/usr/bin/perl $file="testfile1"; #...... grab the file via curl, only do once # system("curl 'http://squirrel.sr.unh.edu/~jraeder/PHYS-795-895-F2017/uploads/testfile1' > $file"); exit; #...... simplest way to read entire file $_=`cat $file`; #print $_; exit; #...... get rid of unwanted characters s/\"/ /g; s/\?/ /g; s/\./ /g; s/\,/ /g; s/\*/ /g; s/\'/ /g; $text=$_; $text=~s/[^a-zA-Z]/ /g; #..... convert all non-letters to blanks # print $_; exit; #...... see what we got #...... loop over lines and print with numbers $k=0; foreach(split('\n',$text)){ $kk=sprintf("%5.5d",$k++); print "$kk $_\n"; } #...... loop over lines and count words %W=(); foreach(split('\n',$text)){ @a=split(' ',$_); foreach $w (@a){ $ww=lc($w); $W{$ww}++; } } #..... find max $m=0; foreach(keys(%W)){ $x=$W{$_}; if($x>$m){ $m=$x; } } print "max count: $m\n"; for($i=$m;$i>5;$i--){ $line=''; $n=0; foreach(keys(%W)){ $x=$W{$_}; if($x == $i){ $line="$line $_"; $n++; } } if(length($line)>0){ print " $i occurrences ($n words): $line\n"; } }