On Sun, Aug 05, 2001 at 07:27:25PM +0200, Birgit Kellner wrote:
> I have two files called html.pl and config.pl, both of which require each
> other.
>
> The subroutine &html_record is contained in the other file, config.pl. I
> want to make the array @hits as well as the values of $numhits and $maxhits
> available to that sub. I know that it works when I "de-privatize" the
> variables, i.e. remove the "my" and the parentheses from the above code.
> But I don't understand enough of perl to figure out (a) whether this is a
> good idea memory-, speed- & style-wise and (b) whether there might be a
> different way. Note that I won't be needing the variable values anymore in
> other subs in html.pl (which, er, is why they were originally declared as
> private variables).
Global variables are rarely a good idea. In this case it just sounds as
though you need to be passing parameters around.
> in html.pl, a subroutine starts like this:
> my (@hits) = @_;
> my ($numhits) = ($#hits+1) / ($#db_cols+1);
There is no need for parentheses around $numhits.
my $numhits = ($#hits+1) / ($#db_cols+1);
> my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits =
> $db_max_hits);
This equivalent line is much simpler I think. No need for the quotes
around 'mh' or for ?:
my $maxhits = $in{mh} || $db_max_hits;
> &html_record;
No need for the &, and pass the parameters.
html_record($numhits, $maxhits, @hits);
If @hits is large you might want to pass it around by reference. You
might also like to consider whether %in should be global.
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]