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.
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();
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.
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.
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.
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:
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
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.
Sign up to Exercism to learn and master Perl with 5 concepts, 83 exercises, and real human mentoring, all for free.