Fellow Monasterians,
I'm attempting to reuse code. I have several scripts, that all have the same exact sub routines. I want to put the common subs in one file and give all the scripts access to it. What's the best way?
SCRIPT 1
#!/usr/bin/perl use warnings; use strict; use CGI::Carp qw(fatalsToBrowser); require "common.lib"; my $name = "frodo"; $name = get_uppercase($name);
COMMON 1
sub get_uppercase { my $name = shift; return uc($name); } 1;
or
SCRIPT 2
#!/usr/bin/perl use warnings; use strict; use CGI::Carp qw(fatalsToBrowser); use Common; my $name = "frodo"; $name = Common->get_uppercase($name);
COMMON 2
package Common; sub get_uppercase { my ($class, $name) = @_; return uc($name); } 1;
Thanks!
In reply to Library file or module for sharing code? by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |