Mike Blezien <[EMAIL PROTECTED]> wrote: : I'm trying to change how data is currently being : added to a file to condense it and make it easier : to work with. : : Below is the code snip that processes and adds : the data to the appropriate file. The current : Output to the file is what I am trying to change : and not having alot of luck. : : The desired output to file is at the bottom of : this post. Any suggestions or help to accomplish : this would be much appreciated. Basically take : the current output to file: : : IE: [snip]
I think one problem is you need to convert all the subcategory files to the new file format *before* you start adding new keywords to the files. Another problem is that you are visualizing your data as it is, instead of changing it to a convenient perl data structure. This whole data set is screaming hash, and you're using an array. Let me clarify. Each line of a subcategory file looks like something this to you: 2D-Animals~animals 2D-Animals~bee 2D-Animals~whale While I see: category keyword ======== ======= 2D-Animals animals 2D-Animals bee 2D-Animals whale You want to end up with: 2D-Animals~animals::bees::whale And I see: 2D-Animals => [ 'animals', 'bees', 'whale', ] # load old file format my $file = "$maincatlogs$MainCat.catlog"; open FH, $file or die "Cannot open $file: $!"; chomp( my @category = <FH> ); close FH; # change it to a perl data structure # a Hash of Arrays (HoA) # see perldsc # my %categories; foreach ( @category ) { my( $category, $keyword )= split /~/; push @{ $categories{ $category } }, $keyword; } # change to the new file format my @file; foreach my $key ( keys %categories ) { push @file, "$key~", join '::', @{ $category{ $key } }; } # change the disk to the new format open FH, ">$file" or die "Cannot open $file: $!"; print sort @file; close FH; You can read more about perl data structures in perldsc. HTH, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc. Mobile Home Specialists 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]