Utrecht has asked for the wisdom of the Perl Monks concerning the following question:

Hello, It may be e little bit a strange question, but I am trying to understand some code. The problem is that in this code two subs are calling each other. How is this possible, or am I interpreting things the wrong way. In the following code the  my $retval = $self->{'timespan'}->init({%{$li}}) is calling sub init, but this sub init is calling sub process again. Here is the necessary code to understand my question:
# for parse modules, sub init is sort of int.main() function sub init { my ( $self, $input ) = @_ ; $self->{'_input_'}->{'_type_'} = 'process'; my $li = $self->update_user_input( $input ); $self->process($li,$input) } # True process module, calls methods from Request::Request_Help. sub process { # The incoming array is split into $self, $li and $input my ($self, $li, $input) = @_ ; # $li is a hash-reference where the keys preforid, order_by and order +_sequence are designated # the values 1, time and ASC respectively. $li->{preforid} = 1; $li->{order_by} = "time"; $li->{order_sequence} = "ASC"; my $retval = $self->{'timespan'}->init({%{$li}}); my %stanet; if ($retval) { foreach my $sta (@$retval) { # Check if sufficient data is already in database [bud_reader]; if +not, process station. $li->{station} = $sta->{sta}; $li->{starttime} = $sta->{starttime}; $li->{endtime} = $sta->{endtime}; my $is_data = $self->{'bud_reader'}->init($li);
Hope anyone knows?

Replies are listed 'Best First'.
Re: subs calling each other
by JavaFan (Canon) on Oct 08, 2008 at 12:35 UTC
    I cannot deduce from your code whether the call to init from process is the same init that calls process. It depends on the package 'sub init' is in, and the package $self->{'timespan'} is blessed into.
Re: subs calling each other
by Xilman (Hermit) on Oct 08, 2008 at 13:57 UTC
    Perhaps it's just a straightforward case of mutual recursion. If so, the recursive call to init() is taken only if the preceding $retval was non-false, otherwise the recursion ends at this call of process().
Re: subs calling each other
by jeanluca (Deacon) on Oct 08, 2008 at 17:13 UTC
    I think that at some point $retval will be empty, so the call init() will not occur and the recursion will stop!