Hi all,

My aim is to write a program that will display the parent-child data in an array. I have an input file called 1.txt. This file contain data such as 10,20,30,40 Foreach data, read from the input file append by .txt to get the sub file data for the next...

The relation is as follows:

1 -> 10, 20, 30, 40 10 -> 100, 101, 102 100 -> no data 101 -> 1011 1011 -> no data 102 -> no data 20 -> no data 30 -> 301, 302 301 -> no data 302 -> no data 40 -> 401, 402 401 -> 4011 4011 -> 40111 40111 -> no data 402 -> no data

(1,10,20,30,40,100,101,102,1011,301,302,401,402,4011,40111 .. are .txt files)

Need to start reading from 1.txt file and the resultant data from that should read subsequent files, finally all data should be stored in an array.

My program works having some problem to store all data... Could anyone please help me to solve this?

My code is given below:

#!/usr/bin/perl @ini_array = (); #input file open(F,"C:/test/1.txt") or die "Can't open 1.txt file"; while(<F>) { chomp; push(@ini_array,$_); } close F; @final_array; foreach $ab (@ini_array) { push(@final_array,$ab); &common($ab); } sub common() { $fl = shift; open(A,"C:/test/$fl.txt") or die "Can't open $fl"; @sublist = <A>; close A; $cnt = scalar @sublist; if ($cnt > 0) { subfl(\@sublist); } else { push(@final_array,@sublist); } } sub subfl() { $arfirst = shift; @ini_array1 = @$arfirst; foreach $ab1 (@ini_array1) { chomp($ab1); push(@final_array,$ab1); &common($ab1); } }
Thanks

Edit: g0n - code tags and formatting


In reply to store parent child relation by Anonymous Monk

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.