They're scripts that report various statistics to DBAs---I won't go into the details---and they're both configurable to output to email, standard output, logfiles, or any combination of the above.
So I wrote a package that simply declares a bunch of our variables.
Then, the script sets the variables to configure:our $usemail = 0; our $mailto = 'root@localhost'; our $mailfrom = 'admin@localhost'; our $mailserver = 'smtp'; our $usestdout = 1;
Okay, this works, but I don't like it. What I'd really like to do is be able to pull in chunks of my code with something like$Reporting::usemail = 1;
So that the sort of reporting would be clear at a glance from the use line, and not be dependent on some long variables further down. In summary, I want to write a package that works sort of like use strict; I can give the use line a list of "options" and it behaves differently depending on what I gave it... something like the following pseudocode:#!/usr/bin/perl use Reporting qw/EMail Stdout/; $Reporting::EMail::to = "root@server"; @report=("Everything is fine.","Nothing is broken."); &Reporting::Send(@report);
Is this possible? Is this easy? Is this really obvious how to do? Am I way off base? Most package-writing tutorials have been really unenlightening. Please help, magnanimous monks...package Reporting; my @sendtasks; if (used "EMail") { use EMail shift @sendtasks,\&EMail::Send; }
In reply to Pragma-like package by dbw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |