Count digits
Exercise: count digits in a file
Given a file like this, that has rows of numbers in it without anything, but a single space in between the numbers. Our task is to count how many times each digit appears.
23 34 9512341
3 34 2452345 5353 67 22
42136357013412
42 5 65 64
Our expected output looks like this:
0 1
1 5
2 9
3 11
4 9
5 8
6 4
7 2
8 0
9 1
Tools for Perl 5
- <a href-"https://perlmaven.com/perl-tutorial">The Perl 5 tutorial in general.
- Perl 5: shift from @ARGV
- Perl 5: open a file for reading or die.
- Perl 5: Arrays
- Perl 5: chomp, remove trailing newlines.
- Perl 5: split, to cut a string into pieces.
Tools for Ruby
- Ruby: ARGV for command line parameters
- Ruby: Open file and read content
- Ruby: Arrays
- Ruby: Iterate over elements of a an array