in reply to Formating Text file

1. When you post code surround it by <code> and </code>. This way the indentation and square brackets will not get lost.

2. Always use the "-w" option and "use strict;" in your programs. This will help identify bugs. The "-T" option is also fun to add to keep yourself honest. If/when you get warnings about the use of tainted data then you sit down and think about the security implications of your program.

3. In your code you create a data structure which has an array of five elemnts which are indexed by a field called "hour". (a) I find it strange that "hour" would only have five values. (b) There is no field called "hour" in the input you parse, nor does the data itself seem to have anything resembling an hour.

4. There seems to be an extra dereferencing on the last line of the first loop.

5. The print statement does not seem to match the number/types of fields you describe should be output (though it's not easy for me to understand from the description exactly what is desired).

Here is your program with a few tweaks. It generates output, but has the warnings about uninitialized values caused by the fact that there is no "hour" input field.

#!c:/perl/bin/perl -wT use strict; my %Data; open (INFILE,"c:/playgnd/sql_result_cf.txt") || die("Could not open file!"); my $header = <INFILE>; while( <INFILE> ) { chomp; my %F; @F{qw(msc_name chunum date count_per_date)} = split /\s*,\s*/; $Data{$F{date}} = { } unless exists $Data{$F{msc_name}}; $Data{$F{date}}->{$F{msc_name}} = [('')x5] unless ref( $Data{$F{date}}->{$F{msc_name}}); $Data{$F{date}}->{$F{msc_name}}[$F{hour}] = $F{count_per_hour}; } foreach my $date (keys %Data) { foreach my $msc_name (keys %{$Data{$date}}) { print join(",", $date, $msc_name, @{$Data{$date}->{$msc_name}}), "\n" ; } } close(INFILE);

This obviously does not do what you want, but it runs and is perhaps it is further in the right direction.

-- Eric Hammond