DCPM: splitting on lookaheads
Steve Marvell
steve at devon-it.co.uk
Fri Oct 31 05:32:56 CST 2003
This is very useful if you don't have a record separator, but instead,
you have concatenated records with a known start block which you need
to keep.
(I've put in a space before the sub so it doesn't bounce)
#!/usr/bin/perl
sub border;
{ local $/; $string = <DATA> }
print border('=',$string);
@records = split (/(?=^fred)/m, $string);
print map { border('-',$_) } @records;
exit;
sub border {
my ($mark,$string) = @_;
$mark x 10,"\n",$string,$mark x 10,"\n";
}
__DATA__
fred 1
dsa
dsa
fred 2
sdaf
dsa
fsda
dsa
More information about the Devoncornwall-pm
mailing list