Sponsoring The Perl Toolchain Summit 2025: Help make this important event another success Learn more

#!/usr/bin/perl
# Learning RPerl, Chapter 6, Exercise 1
# Accept one input given (first) name, and print the corresponding family (last) name
# [[[ HEADER ]]]
use RPerl;
use strict;
our $VERSION = 0.001_000;
# [[[ CRITICS ]]]
## no critic qw(ProhibitUselessNoCritic ProhibitMagicNumbers RequireCheckedSyscalls) # USER DEFAULT 1: allow numeric values & print operator
## no critic qw(ProhibitExplicitStdin) # USER DEFAULT 4: allow <STDIN> prompt
# [[[ SUBROUTINES ]]]
sub given_to_family_name {
{ my void $RETURN_TYPE };
my string_hashref $names = {
fred => 'flintstone',
barney => 'rubble',
wilma => 'flintstone'
};
print 'Please input a given (first) name in all lowercase, then press <ENTER>:', "\n";
my string $given_name = <STDIN>;
chomp $given_name;
if ((not exists $names->{$given_name}) or (not defined $names->{$given_name})) {
croak 'ERROR: No family (last) name found for given (first) name ', $given_name, ', croaking', "\n";
}
print 'The family (last) name of ', $given_name, ' is ', $names->{$given_name}, q{.}, "\n";
return;
}
# [[[ OPERATIONS ]]]
given_to_family_name();