I have a script that prints out database records after a search operation.
For each hit in the database, it calls the subroutine sub_one to first turn
the record with the hit into a hash and then print out results in html.
Now, there's one of these hash values which I would then like to use in a
different sub, and I am wondering how to best go about it.
Here's the code so far:
##### main code #####################
my ($numhits, @hits) = @_; # @_ contains output from a different script
for (0 .. $numhits - 1) {
&sub_one(&array_to_hash($_, @hits));
}
########## end main code
####### begin subroutines
sub_one {
my %rec = @_;
print qq|<br>here is some code with $rec{'one'}, $rec{'two'},
$rec{'three'}.<br>|;
my $value = $rec{'three'};
}
sub_two {
my $value = $_[0];
&query($value);
}
########### end subroutines
I guess I could just call sub_two with $value as an argument from sub_one:
&sub_two($value).
But is there a possibility to first return $value from sub_one to the main
code and then do something with it there?
In other words, if I add "return $value" to sub_one, can I then use it in
the main code like this:
########## main code #################
my ($numhits, @hits) = @_;
for (0 .. $numhits - 1) {
&sub_one(&array_to_hash($_, @hits));
my $value = $_[0]; # is $_[0] here the return argument from sub_one?
}
######## end main code
Birgit Kellner
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]