Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.51 KB | None | 0 0
  1. use strict;
  2.  
  3. use Data::Dumper;
  4.  
  5. my %char_counter;
  6.  
  7. # how to handle no args?
  8. open(FIN, '<', $ARGV[0]) or die("Can not open file \"$ARGV[0]\"");
  9.  
  10. while (<FIN>)
  11. {
  12.     my $char;
  13.     foreach $char (split('', $_))
  14.     {
  15.         if ($char =~ m/[[:print:]]/g)
  16.         {
  17.             $char_counter{$char} += 1;
  18.         } else
  19.         {
  20.             $char_counter{ord($char)} += 1;
  21.         }
  22.     } # end foreach
  23. }
  24. close(FIN);
  25.  
  26. # why we have to put "\" before "%"?
  27. print Dumper(\%char_counter);
  28.  
  29. exit(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement