Perl library (perl4 style)
examples/modules/library.pl
$base = 10; sub add { validate_parameters(@_); my $total = 0; $total += $_ for (@_); return $total; } sub multiply { } sub validate_parameters { die 'Not all of them are numbers' if grep {/\D/} @_; return 1; } 1;
examples/modules/perl4_app.pl
#!/usr/bin/perl require "examples/modules/library.pl"; print add(19, 23); print "\n"; print "$base\n";
The 1; at the end of the library is needed in order to make sure the compilation of library.pl returns a true value.
Otherwise one could get an error such as this one:
examples/modules/library.pl did not return a true value