Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data manipulation 8

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
CA
Hi,

I trying to find a simple way to re-structure data and then create a new flat file.

You will see the logic with the data below.

From this format:

Code:
#A59993
TRR[1T1-1T3,1Y7,1W9,2R1-2R3]
#A53700
TQQ[1A6,1C0-1C4,1P0]

To this format:

Code:
A59993|TRR1T1,TRR1T2,TRR1T3,TRR1Y7,TRR1W9,TRR1R1,TRR2R1,TRR2R2,TRR2R3
A53700|TQQ1A6,TQQ1C0,TQQ1C1,TQQ1C2,TQQ1C3,TQQ1C4,TQQ1P0

Let me know if it's not clear enough.

Thank you in advance.
 
Ooops.. Didn't add the right portion of coding. With the one above, I will only get the ID number in the flat file obviously.

Code:
foreach my $keys (reverse sort keys %HoH){
   print "#$keys\n"; 
   foreach my $i (reverse sort keys %{$HoH{$keys}}) {
      print "$i\[";
      my $y = 0;
      foreach  my $n (sort keys %{$HoH{$keys}{$i}}) {
         my $num = keys %{$HoH{$keys}{$i}};
         $y++;
         print "$n$HoH{$keys}{$i}{$n}->[0]";
         print "\-$n$HoH{$keys}{$i}{$n}->[$#{$HoH{$keys}{$i}{$n}}]" if (scalar @{$HoH{$keys}{$i}{$n}}>1);
         print ',' if $y < $num;
      }
      print "]\n";
      [b]print OUT;[/b]
   }
}
 
add the file handle to each print line:

Code:
foreach my $keys (reverse sort keys %HoH){
   print OUT "#$keys\n";
   foreach my $i (reverse sort keys %{$HoH{$keys}}) {
      print OUT "$i\[";
      my $y = 0;
      my $num = keys %{$HoH{$keys}{$i}};
      foreach  my $n (sort keys %{$HoH{$keys}{$i}}) {
         $y++;
         print OUT "$n$HoH{$keys}{$i}{$n}->[0]";
         print OUT "\-$n$HoH{$keys}{$i}{$n}->[$#{$HoH{$keys}{$i}{$n}}]" if (scalar @{$HoH{$keys}{$i}{$n}}>1);
         print OUT ',' if $y < $num;
      }
      print OUT "]\n";
   }
}

The code block above builds up each line of the file as it goes through the loops so you need to use the filehandle at each print command to get it all printed to a file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top