in reply to Re^2: log file sorting
in thread log file sorting
ah, thanks for notifying me about the paragraph tags, i somehow missed them reading about them
No problem. Just go to your original question and fix the markup.
As for your programming problem, I think you're making it harder than it needs to be.
For example there's no need to store your data to disk twice, and read it again. Here's what I'd do, in non-tested perl code, with some blanks left for you to figure out:
# store all data here: my %data; while (<INPUT>){ chomp my @items = sort split m/,/; my %seen; # number the occurrences of data points, and put them into a hash for (@items) { my ($key, $val) = split m/ /, $_, 2; my $index = ++$seen{$key}; push @{$data{"$key$index"}}, $val; } } # now all data should be in the hash %data. use Data::Dumper; print Dumper \%data; # now print it: my @keys = sort keys %data; while (keys %data) { for (@keys) { if (exists $data{$_}) { # print it out here # then remove it shift @{$data{$_}}; delete $data{$_} unless @{$data{$_}}; } else { # print a placeholder here } } }
The idea is to keep a list of all data values for each label, in your case ['#', '#'] for A1, ...
The choice of a clever data structure (ie one that fits the way you want to access it in your code) makes it much easier.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: log file sorting
by numberninja (Initiate) on Aug 04, 2008 at 17:30 UTC |