[Canberra-pm] do read-local.config

Michael James Michael.James at csiro.au
Thu Mar 30 19:39:46 PST 2006


I asked:
> > What's the point of "do"ing a config file
> > if it can't pass variables? 

On Thu, 30 Mar 2006 10:28 pm, you wrote:
> The file that is being "done"
> can *return* a value to the calling code: 
> 
>    my $config = do "configuration.pl";
> 
> If the configuration file happens to return a hash-reference,
> then we can return a whole bunch of useful configuration at once.
> For example, 'configuration.pl'  may contain:
> 
>  return {
>     directory => "/usr/local/example",
>     timeout   => 30,
>     hostname  => "www.example.com",
>  }
> 
> This is much less error-prone than creating or modifying variables
> and expecting the other file to know what they're called.
> By using: 
> 
>   my $config = do "configuration.pl";
> 
> we may it very clear to anyone reading the code
> that we expect to store the result of our file
> in the $config variable. 
> 
> More notes can be found at:
> http://perl.net.au/wiki/Using_do_for_configuration . 

Excellent! Thanks, that's made it clear.

But what if I want the "doer" perl script
 to pass configuration to the "done" script?

In the code I've been given, they've used a "system" call,
 adding all the (user supplied) parameters to the string executed.
Very insecure.

One way would be to add the second file to the end of the first,
 but for historical reasons, I'd prefer to keep them separate files.

Is there a way for the "doer" script to pass variables to the "done"?
Or is some variant of "system" still the best way?


-- 
Michael James                         michael.james at csiro.au
System Administrator                    voice:  02 6246 5040
CSIRO Bioinformatics Facility             fax:  02 6246 5166

No matter how much you pay for software,
 you always get less than you hoped.
Unless you pay nothing, then you get more.


More information about the Canberra-pm mailing list