iaw4 has asked for the wisdom of the Perl Monks concerning the following question:
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 main; use cacher "/etc"; my $fstab_wc = cacher::wc("fstab");
so, how do I get the arguments in a simple way?? /iaw4package 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]}); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Skeleton For Import to Package?
by almut (Canon) on Jul 28, 2010 at 14:17 UTC | |
by iaw4 (Monk) on Jul 28, 2010 at 15:14 UTC | |
by almut (Canon) on Jul 28, 2010 at 15:21 UTC |