Skip to content
/ cpd.pl Public

count frequencies of different numbers and show an accumulative frequency.

Notifications You must be signed in to change notification settings

hlmarkc/cpd.pl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

cpd.pl

#count frequencies of different numbers and show an accumulative frequency.

!usr/bin/perl -w

#first to identify if there is a list or a file if (-e $ARGV[0]){ @a=(); open (IN, "<$ARGV[0]"); while (){ chomp($); push (@a, $); } close IN; else { @a = @ARGV; }

#make the data after re-arrangement (from small value to large) to be a new list @sa = sort {$a <=> $b} @a; print "@sa\n";

#count individual numbers $n = $sa[0]; $f = 1; $sum = 0; for ($i = 1; $i&lt;=$#sa; $i=$i+1){

      if ($sa[$i] eq $n) {
          $f = $f + 1;
      }
      else {
      $sum += $f;
      print "$n\t$sum\n";
      $n = $sa[$i];
      $f = 1;
      }
  }
 print "$n\t$sum\n";

About

count frequencies of different numbers and show an accumulative frequency.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published