Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Consolidating data from lots of different sources

by tlm (Prior)
on Jun 08, 2005 at 21:52 UTC ( [id://464857]=note: print w/replies, xml ) Need Help??


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).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://464857]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found