Tracks
/
Perl
Perl
/
Exercises
/
Booking up for Beauty
Booking up for Beauty

Booking up for Beauty

Learning Exercise

Introduction

Packages and Modules

Importing

A module is usually loaded with the use keyword. This will both load and call the import method on it, importing any exported symbols.

Symbols in the package's @EXPORT array will be imported by default. Symbols in the package's @EXPORT_OK array must be imported explicitly.

Exporting

For a symbol to be imported, it must first be exported. The Exporter module is included with Perl and is one of the most convenient options for exporting.

Defining the module:

package Foo;

use Exporter ('import');
our @EXPORT_OK = ('bar');

sub bar { ... }

Using the module:

use Foo ('bar');

bar();

Core Modules

Along with Exporter, Perl has a large variety of core modules available to use. Some examples useful for exercises you may encounter here include List::Util, Time::Piece, and Math::BigRat.

CPAN

In additon to core modules, CPAN has thousands of additional modules created by the Perl community available for installation. The Perl track uses a cpanfile to install a selection of modules which can be used with Exercism's Perl test runner.

Instructions

In this exercise you'll be working on an appointment scheduler for a beauty salon.

You have three tasks, which will all involve appointment dates.

1. Check if an appointment has already passed

Implement the appointment_has_passed subroutine that takes a date string and checks if the appointment was somewhere in the past:

appointment_has_passed("2019-07-25T13:45:00")
// => true

Date strings will be passed in ISO 8601 datetime format: YYYY-mm-ddTHH:MM:SS

You will need to implement the private _parse_datetime subroutine. A couple of modules are suggested for you:

2. Check if appointment is in the afternoon

Implement the is_afternoon_appointment function that takes a date string and checks if the appointment is in the afternoon (>= 12:00 and < 18:00):

is_afternoon_appointment("2019-07-25T13:45:00")
// => true

3. Describe the time and date of the appointment

Implement the describe_appointment function that takes a date string and returns a description of that date and time:

describe_appointment("2019-07-25T13:45:00")
// => "You have an appointment on 07/25/2019 1:45 PM"

Note the hour is in the range 0-12 and does not have a leading zero or space.

Edit via GitHub The link opens in a new window or tab
Perl Exercism

Ready to start Booking up for Beauty?

Sign up to Exercism to learn and master Perl with 5 concepts, 65 exercises, and real human mentoring, all for free.