in reply to Re: Split Function - Positions
in thread Split Function - Positions
One way to do this is to capture the junk along with the substrings
This is a fine use for the special treatment of capturing parentheses in the first (regex) argument to split:
my @chunks; my @start_pos; my $pos = 0; foreach my $chunk ( split /(X+)/, $string ) { unless ( $chunk =~ /^X/ ) { push @start_pos, $pos; push @chunks, $chunk; } $pos += length $chunk; }
|
|---|