in reply to Consolidating data from lots of different sources

The following code assumes that the different data lines are consistent (i.e. for a given ID there is a unique non-empty value for each field):

use strict; use warnings; my %data; while ( <DATA> ) { my ( $id, @fields ) = split /\s*,\s*/, $_, -1; for my $i ( 0..$#fields ) { $data{ $id }[ $i ] = $fields[ $i ] if length $fields[ $i ]; } } __END__

Update:I've attempted to fix one of the problems pointed out by ikegami below (specifically, added the -1 argument to split). I still focus only on the problem of consolidating from various lines, which I think is what the OP was having problems with, and ingore the issue of output.

the lowliest monk

Replies are listed 'Best First'.
Re^2: Consolidating data from lots of different sources
by ikegami (Patriarch) on Jun 08, 2005 at 22:04 UTC

    Your solution doesn't output anything.

    It leaves (any trailing whitespace including the) newlines in the data.

    And only creates two fields for Srv_0G, causing the trailing comma to be omitted from the output (which I suppose could be fixed at print-time).