Skip to content

Instantly share code, notes, and snippets.

@damienix
Created December 12, 2010 16:43
Show Gist options
  • Select an option

  • Save damienix/738162 to your computer and use it in GitHub Desktop.

Select an option

Save damienix/738162 to your computer and use it in GitHub Desktop.
Prints words' statistics for file.
#!/usr/bin/perl
#: Date : 2010-12-12
#: Author : Damian Skrodzki <damienix1@gmail.com>
#: Description : Prints words statistics for file.
open(F, "file") || die("Could not open file!");
@content=<F>;
close(F);
@words=split(/\W+/, lc "@content");
foreach $w (@words) {%ctrs->{$w}++;}
foreach $w (sort {$ctrs{$b} <=> $ctrs{$a}} keys(%ctrs)) {print "$ctrs{$w} - $w\n";}
@damienix
Copy link
Copy Markdown
Author

add reading from all lines (not only first)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment