it might be one or two or three or more newlines in the last field
Well it'd be nice if your sample data would reflect that. Anyhow. I'd solve this using a simple algorithm rather than a complicated regex that backtracks god knows how often with all these .*
Consider:
use warnings;
use strict;
my @record;
while (<DATA>)
{
if (/^\d+\~/ && @record)
{
print join (" ", @record), "\n";
@record = ();
}
chomp;
push @record, $_;
}
print join (" ", @record), "\n";
__DATA__
99~Markus~Holli~Mobilenum:
1234-567 , from Earth
Europe
White
Human
98~Mahesh~Babu~Mobilenum:
5678-901 , from Earth
India
Brown
Human
Output
99~Markus~Holli~Mobilenum: 1234-567 , from Earth Europe White Human
98~Mahesh~Babu~Mobilenum: 5678-901 , from Earth India Brown Human
holli
You can lead your users to water, but alas, you cannot drown them.
|