Hi monks, I am having a number of files in a hierarchial order. Something like It is not like one file inside another, only filenames will be there... Say inside Main, three filenames will be there,sub1.sub2,sub3..........
Main --------------------------------------------------------- sub1 sub2 sub3 sub4 -------------------------------------------------------- sub11 sub21 sub31 sub41 sub12 sub22 sub32 sub42 sub13 sub23 sub33 sub43 ___________________-____________________________________
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 open
Main sub1 sub11 sub12 sub13
then again go back to Main
sub2 sub21 sub22 sub23
then again go back to Main
sub3 sub31 sub32 sub33
etc............. How can I do it with recursion???????????? i tried it like
#! /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"; }
I am inside the infinite loop...How can i print it correctly. Thanks in advance

In reply to Recursive function in perl by ashok13123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.