f1 calls (f2)
f2 calls (f3,f4)
f3 calls nothing
f4 calls f5
f5 calls nothing
####
f1->f2->f3
f1->f2->f4
f2->f4->f5
####
key value
f1 f2
f2 f3,f4
f3
f4 f5
f5
####
my %calls; #has all the function call information
my $length = 3; #the length of function chains
my @chain_store; #array of array, to save the chains
while (($key, $value) = each %calls) {
my @chain = ();
push @chain, $key;
get_chains($value, \@chain);
}
sub get_chains {
my $value = shift;
my $chain_ref = shift;
my @chain = @{$chain_ref};
foreach my $val @{$value} {
push @chain, $val;
my $is_present = 1;
for (my $count = 0; $count < $length; $count++) {
if (exist($calls{$val})) {
get_chains($calls{$val})
} else {
$is_present = 0;
last;
}
}
if ($is_present) {
push @chain_store, @chain;
}
}
}