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

Dispatch Table

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


sub add {
    my ($x, $y) = @_;
    return $x+$y;
}

sub multiply {
    my ($x, $y) = @_;
    return $x*$y;
}

my %dispatch = (
    '+'  => \&add,
    '*'  => \&multiply,
);

my $op = '+';
print $dispatch{$op}->(2, 3), "\n";