Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Parsing of multiple lines into fields 1

Status
Not open for further replies.

max1x

Programmer
Jan 12, 2005
366
US
I have been able to parse the data from many blocks and lines into single fields, but am running into a brain freeze for further correlation. Data looks as follows and I need to make it look like FINAL data. Any pointers and my brain will thank you.

DATASET
sig1 a b c d e
sig1 f g h i j
sig2 a b c d e
sig2 f g h i j

FINAL DATA
sig1 a f b g c h d i e j
sig2 a f b g c h d i e j

 
How about something like:
Code:
my %data;

while (<DATA>) {
	my ($key, @rest) = split;
	push @{$data{$key}}, @rest;
}

foreach (sort keys %data) {
	print join(" ", $_, @{$data{$_}}), "\n";
}

__DATA__
sig1 a b c d e
sig1 f g h i j
sig2 a b c d e
sig2 f g h i j
Of course you'll want to put some error checking in, but hopefully that will get you going.
 
harsh, yes, you definately got me going...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top