in reply to amalgamate similar lines
#!/usr/bin/perl -w use strict; use Data::Dumper::Simple; my %first_two; while (<DATA>) { chomp; my ($key, $remainder) = $_ =~ /([a-z]+\|[a-z]+)\|([a-z]+)/; if (exists $first_two{$key}) { $first_two{$key} .= ",$remainder"; } else { $first_two{$key} = $_; } } print Dumper(%first_two); __DATA__ aaa|bbb|ccc ddd|eee|fff ddd|eee|xxxxx hhh|iiii|jjjjjj
Which gives:
%first_two = ( 'aaa|bbb' => 'aaa|bbb|ccc', 'hhh|iiii' => 'hhh|iiii|jjjjjj', 'ddd|eee' => 'ddd|eee|fff,xxxxx' );
There are probably many more elegant ways to do it, but that's just the first thing that occurred to me.
Cheers,
Darren :)
|
|---|