Dear Perl wizards:
I need to learn how to import arguments into a module. For example, I want
to create a module that stores some stuff for faster later access. I
understand that this can be done in different ways, but let's do it with a "static" module. So here is a simplified version of what I want to
accomplish;
package main;
use cacher "/etc";
my $fstab_wc = cacher::wc("fstab");
This is really a package that is all static. My package itself should do
the following: pick up the argument from the use statement (here '/etc') or
use a default (say, '/tmp'), and build a hash.
package cacher;
use strict;
use warnings;
use warnings FATAL => qw{ uninitialized }; # larry, this should have b
+een part of warnings.
...
BEGIN {
my %cachehash;
my @saved_pkg_args;
sub import {
... pick off the arguments, here /etc/ ...
... allow for a default ...
... how?? ...
}
use File::Glob qw(bsd_glob);
foreach my $dir (bsd_glob(@saved_pkg_args, !"GLOB_NOCHECK")) {
foreach my $file (bsd_glob("$dir/*")) {
$cachehash{"$dir/$file"} = `wc $dir/$file`;
}
}
sub wc { return($cachehash{$_[0]}); }
}
so, how do I get the arguments in a simple way??
/iaw4