Perl typing test
Perl is famous for packing a lot into one line, and its sigils make it unlike anything else to type: $ for single values, @ for arrays and % for hashes. Add my declarations, \n in double-quoted strings, => in hashes and -> to reach into references, and every line is a symbol workout.
What you'll type in Perl
$and@sigils, as inmy $i,@_and@$out.mybefore each new variable.->{ }to reach into a hash reference, as in$node->{value}.=>in hash literals like{ value => $value }.\nat the end of printed strings.unless, and conditions after the statement they control, as inreturn $out unless $node;.
Example: FizzBuzz in Perl
Each branch fits on one line, in braces, and every printed string ends with \n.
for my $i (1 .. 15) {
if ($i % 15 == 0) { print "FizzBuzz\n" }
elsif ($i % 3 == 0) { print "Fizz\n" }
elsif ($i % 5 == 0) { print "Buzz\n" }
else { print "$i\n" }
}
Tips for typing Perl faster
$is Shift + 4 and@is Shift + 2 on US keyboards. Learn both by touch, because Perl uses them constantly.- Watch
$node->{left}: three symbols in a row between the name and the key. - Perl lets a condition come after the statement it controls, as in
return $out unless $node;. Read the whole line before you start typing it.
All 20 Perl programs
Every program is real, working Perl. Choose one to start typing it straight away.
Beginner
- Hello, World!Print a greeting.
- Count to fivePrint the numbers 1 to 5.
- Celsius to FahrenheitConvert 100 °C to Fahrenheit.
- Sum a listAdd up 3, 1, 4, 1, 5.
- Find the largestFind the biggest number in a list.
- Count vowelsCount the vowels in "keyboard".
Intermediate
- Reverse a stringTurn "hello" into "olleh".
- FizzBuzzFizz for 3s, Buzz for 5s, 1 to 15.
- FactorialA recursive function, called with 5.
- FibonacciPrint the first ten Fibonacci numbers.
- Greatest common divisorEuclid's algorithm for 48 and 18.
Advanced
- Primes to 20Print every prime up to 20.
- PalindromeCheck whether "racecar" reads the same backwards.
- Word countCount the words in a sentence.
- Bubble sortSort 5, 2, 9, 1, 7 by swapping neighbours.
- Binary searchFind 7 in a sorted list by halving.
Expert
- QuicksortSort a list by partitioning around a pivot.
- Binary search treeBuild a tree, then read the values back in order.
- Shortest path (BFS)Breadth-first search through a small graph.
- N-QueensCount the ways to place 6 queens so none attack.
How the test works
The timer starts on your first key and stops once every character is right. Press Enter for a new line and the indentation is filled in for you. A wrong key shows in red and counts as a mistake; press Backspace to go back and fix it. Your best time for each program is saved in your browser. Read more about how speed and accuracy are calculated, or get tips for typing code faster.