Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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:
Thanks#!/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); } }
Edit: g0n - code tags and formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: store parent child relation
by TedPride (Priest) on May 18, 2006 at 08:00 UTC | |
by Anonymous Monk on May 18, 2006 at 08:37 UTC | |
|
Re: store parent child relation
by turo (Friar) on May 18, 2006 at 08:13 UTC | |
by Anonymous Monk on May 18, 2006 at 08:41 UTC |