package Navigation;
sub turn_towards_heading {
.. code here ..
}
sub turn_towards_port {
.. code here ..
}
1;
The package declaration at the beginning of this
file tells Perl to insert Navigation:: in front of
most names within the file: Thus, the code above practically says:
sub Navigation::turn_towards_heading {
.. code here ..
}
sub Navigation::turn_towards_port {
.. code here ..
}
1;
Now when Gilligan uses this file, he simply adds
Navigation:: to the subroutines defined in the
library, and leaves the Navigation:: prefix off
for subroutines he defines on his own:
#!/usr/bin/perl
require 'navigation.pl';
sub turn_toward_port {
Navigation::turn_toward_heading(compute_heading_to_island( ));
}
sub compute_heading_to_island {
.. code here ..
}
.. more program here ..
So, in
navigation.pl, you can use variables such as:
package Navigation;
@homeport = (21.1, -157.525);
sub turn_toward_port {
.. code ..
}
(Trivia note: 21.1 degrees north, 157.525 degrees west is the
location of the real-life marina where the opening shot of a famous
television series was filmed.)
You can refer to the @homeport variable in the
main code as:
@destination = @Navigation::homeport;