=head1 NAME FunLib.pm - a simple function library example =head1 SYNOPSIS use FunLib qw/:all/; use FunLib qw/sum circle_sector_area/; =head1 DESCRIPTION Library of useful mathmatical calculations. =head1 USAGE What is the sum of an array of numbers? my @nums = (10, 14, 25, 49); my $result = sum(@nums); What is the area of a circle sector with a radius of 4 and a 20 degree angle? my $area = circle_sector_area(4,20); What globals are available? PI - a constant for PI $level - a global scalar for the levels =head1 BUGS none known =head1 AUTHOR David Scott <leapingfrog@yahoo.com> =head1 FUNCTIONS Functions follow in alphabetic order: =over 4 =cut use strict; use warnings; package FunLib; use constant PI => 4 * atan2(1,1); our $level = 10; BEGIN { use Exporter( ); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = "1.00"; # make a version for changes @ISA = qw/Exporter/; # inherit from Exporter @EXPORT = ( ); # don't export without asking # create Export tags for convenience %EXPORT_TAGS = ( all => [ qw/ sum sum circle_sector_area PI $level / ], calculate => [ qw/ sum circle_sector_area / ], globals => [ qw/ PI $level / ], ); @EXPORT_OK = qw/ sum circle_sector_area PI $level /; } =item $result = sum(@something) sum numbers in @something and return the $result =cut sub sum { my (@something) = @_; my $result = 0; foreach my $item (@_) { $result += $item; } return $result; } =item $area = circle_sector_area($radius, $degrees); Return the area of a circle sector given the $radius, the angle in $degrees, and the global constant, PI. =cut sub circle_sector_area { my ($radius, $degrees) = @_; return ($radius * $radius * (PI / 360)); } =back =cut 1; # enables Perl to know it loaded properly