Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercise: create counter

Create a script with a function called count() which is capable of maintaining several counters.

#!/usr/bin/perl 
use strict;
use warnings;

print counter('a'), "\n";  # 1
print counter('b'), "\n";  # 1
print counter('a'), "\n";  # 2
print counter('c'), "\n";  # 1
print counter('a'), "\n";  # 3
print counter('a'), "\n";  # 4
print counter('b'), "\n";  # 2