in reply to text parsing question
REGEX WITH SPACE DELIMITERmy @nums; push @nums, pos() - 1 while m/-[^-]/g;
SUBSTR WITH SPACE DELIMITERmy @nums; push @nums, pos() - 1 while m/- /g;
Note that all of the above have to have a space added to the end beforehand, and also removed afterwards if you intend to use the line for anything else:my (@nums, $pos); push @nums, $pos while $pos = index($_, '- ', $pos) + 1;
$_ = ' ---------- ------------------------- -------- ---- ------ +------------------- ----- ---- ----------- -----------'; $_ .= ' '; my (@nums, $pos); push @nums, $pos while $pos = index($_, '- ', $pos) + 1; print join(' ', @nums); chop;
|
|---|