That is main link is Main Under main-> sub1,sub2,sub3,sub4 Under sub1->sub11,sub12,sub13,sub14 Under sub2->sub21,sub22,sub23,sub24 Like this i can have any number of links under sub11 also. I wanted to write a program which will print the link names depending on the level we are specifying using recursion. Say if i am specifying the depth as 3,it shold openMain --------------------------------------------------------- sub1 sub2 sub3 sub4 -------------------------------------------------------- sub11 sub21 sub31 sub41 sub12 sub22 sub32 sub42 sub13 sub23 sub33 sub43 ___________________-____________________________________
then again go back to MainMain sub1 sub11 sub12 sub13
then again go back to Mainsub2 sub21 sub22 sub23
etc............. How can I do it with recursion???????????? i tried it likesub3 sub31 sub32 sub33
I am inside the infinite loop...How can i print it correctly. Thanks in advance#! /usr/bin/perl @listofLinks=qw(Main) &fileview sub fileview { @listLinks=@_; #print @listLinks; foreach $val (@listLinks) { if ($count<2) { $count++; @newlinks=getlinks($val); &fileview(@newlinks); } &printFile($val); } } $count--; last if($count==0); } sub getlinks { $file=$_[0]; open (FH,$file); @arr=<FH>; return(@arr); } sub printFile { open(FH,"$_[0]"); @arr=<FH>; print "@arr\n"; }
In reply to Recursive function in perl by ashok13123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |