in reply to Character Text Delimiters
An alternative to the various regular expression approaches would be to use index and substr to work along the text. This method makes no attempt at coping with the potential fragilities of the data format so YMMV.
use strict; use warnings; use 5.010; my $text = q{xxxAAsgdhsdgABudhwuACedAGuwydADwieuhwiudAEudwdfuw}; my $tag = shift || q{AA}; my $limit = q{ZZ}; my @records = (); my $prevPosn = index $text, $tag, 0; die qq{ERROR: First record '$tag' not found in text\n} if $prevPosn == -1; warn qq{WARNING: First record '$tag' not at start of text\n} unless $prevPosn == 0; while ( ( my $posn = index $text, ++ $tag, $prevPosn + 2 ) != -1 ) { push @records, substr $text, $prevPosn, $posn - $prevPosn; $prevPosn = $posn; last if $tag eq q{ZZ}; } push @records, substr $text, $prevPosn; say qq{>$_<} for @records;
The output.
>AAsgdhsdg< >ABudhwu< >ACedAGuwyd< >ADwieuhwiud< >AEudwdfuw<
I hope this is of interest.
Cheers,
JohnGG
|
|---|