[Canberra-pm] do read-local.config

Jacinta Richardson jarich at perltraining.com.au
Thu Mar 30 20:23:08 PST 2006


Michael James wrote:

> 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?

It's very hard to answer this question without seeing your code.  But I suspect
the correct answer is for you to wrap the whole thing up as a subroutine, give
the file a useful name and package, and then "use" that module and call the
subroutine where-ever you need it, passing in the parameters as arguments.

It depends on what's in the file, but for the by and large such a procedure
would work:

------------------- main.pl
#!/usr/bin/perl -w
use strict;
use Second;

# Usual code.

# Do second half:
my $return = Second::second_half($arg1, $arg2, $arg3, ... );

# finish up.

----------------------- Second.pm
package Second;

sub second_half {
	my ($arg1, $arg2, $arg3, ...) = @_;
	
	# check arguments

	# all the previous stuff

	return $something;
}

1;  # must appear at end of module
-----------------------------

Of course if you have the time, skill and power to refactor the two scripts into
one then that may well be easier for future maintainers.

	Jacinta

-- 
   ("`-''-/").___..--''"`-._          |  Jacinta Richardson         |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +61 3 9354 6001        |
  _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
 (il),-''  (li),'  ((!.-'             |   www.perltraining.com.au   |




More information about the Canberra-pm mailing list