Hi to Everyone,
This is the first time that i write here. I have several files, this is the node:
filename: 0_IP_017.CSV
440Z0220-932§other information 623Z5400-1§other information 623Z5400-1§other information 623Z5400-18other information 623Z5400-18§other information 623Z5400-3§other information 623Z5420-1301§other information 623Z5420-1307§other information 7010902H01§other information 7010900H01§other information 623Z5466-1013§other information 623Z5466-1015§other information 623Z5465-1039§other information 623Z5465-1041§other information 623Z5465-1001§other information 623Z5420-3301§other information 623Z5465-41§other information 623Z5462-1001§other information 623Z5462-1003§other information 7010902H01§other information 623Z5420-3307§other information B3-15838§other information 623Z5422-3307§other information

the leafs:
filename: 1_623Z5462-1003.CSV
623Z5462-1003§Other information 623Z5468-1§Other information 623Z5468-9§Other information 623Z5468-7§Other information 623Z5468-5§Other information CA623Z5462-1003§Other information BACD40AC36B30§Other information 623Z5469-7§Other information 623Z5462-3§Other information

filename: 1_623Z5465-1001.CSV
623Z5465-1001§other information 623Z5465-1§other information 623Z5465-11§other information CA623Z5465-1001§other information

and I have to create a file like this:
0 440Z0220-932§other information 1 440Z0220-932§other information 1 623Z5400-1§other information 1 623Z5400-1§other information 1 623Z5400-18other information 1 623Z5400-18§other information 1 623Z5400-3§other information 1 623Z5420-1301§other information 1 623Z5420-1307§other information 1 7010902H01§other information 1 7010900H01other information 1 623Z5466-1013§other information 1 623Z5466-1015§other information 1 623Z5465-1039§other information 1 623Z5465-1041§other information 1 623Z5465-1001§other information 1 623Z5420-3301§other information 1 623Z5465-41§other information 1 623Z5462-1001§other information 2 623Z5465-1§other information 2 623Z5465-11§other information 2 CA623Z5465-1001§other information 1 623Z5462-1003§other information 2 623Z5462-1003§Other information 2 623Z5468-1§Other information 2 623Z5468-9§Other information 2 623Z5468-7§Other information 2 623Z5468-5§Other information 2 CA623Z5462-1003§Other information 2 BACD40AC36B30§Other information 2 623Z5469-7§Other information 2 623Z5462-3§Other information 1 7010902H01§other information 1 623Z5420-3307§other information 1 B3-15838§other information 1 623Z5422-3307§other information

And here my code:
#!/usr/bin/perl $folder_IN=$ARGV[0]; $level=0; $finaltreefile="./final.CSV"; $rootfile=`ls $folder_IN/$level*.CSV`; print "rootfile: $rootfile\n"; &treebuilder($rootfile); sub treebuilder{ $PRESENTLEVELFILE=shift; print "File level $level : $PRESENTLEVELFILE\n"; $level++; open(PRESENTLEVELFILE); while ($leafline=<PRESENTLEVELFILE>){ print "Leggo $leafline\n"; chomp($leafline); if ($. == 1){ if($PRESENTLEVELFILE =~ /^0*/i){ open(FINAL,">$finaltreefile"); print FINAL "0 $leafline\n"; close(FINAL); } next; }else{ print "next level=$level\n"; @element=split('§',$leafline); chomp($element[0]); print "Find $element[0]\n"; $NEXTLEVELFILE=$folder_IN."/".$level."_".$element[0].".CSV"; chomp($NEXTLEVELFILE); print "Check if file exists: $NEXTLEVELFILE\n"; if (-e $NEXTLEVELFILE){ print "$NEXTLEVELFILE !esiste!\n"; &treebuilder($NEXTLEVELFILE); open(FINAL,">>$finaltreefile"); $level++; print FINAL "$level $leafline\n"; close FINAL; } print "$NEXTLEVELFILE ?not exists?\n"; open(FINAL,">>$finaltreefile"); print FINAL "$level $leafline\n"; close FINAL; } } }

executing my code I only can have this:
0 440Z0220-932§other information 1 440Z0220-932§other information 1 623Z5400-1§other information 1 623Z5400-1§other information 1 623Z5400-18other information 1 623Z5400-18§other information 1 623Z5400-3§other information 1 623Z5420-1301§other information 1 623Z5420-1307§other information 1 7010902H01§other information 1 7010900H01§other information 1 623Z5466-1013§other information 1 623Z5466-1015§other information 1 623Z5465-1039§other information 1 623Z5465-1041§other information 1 623Z5465-1001§other information 1 623Z5420-3301§other information 1 623Z5465-41§other information 1 623Z5462-1001§other information 2 623Z5465-1§other information 2 623Z5465-11§other information 2 CA623Z5465-1001§other information

where I do a mistake?

In reply to create a level csv 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.