Once a simple space separated token rule has been enforced, then a simple split statement suffices. I don't know if this is true in this case, but often running a couple of simple regex/split statements can execute faster than a single complicated regex.
use warnings; use strict; while (my $line = <DATA>) { chomp $line; print "Input Line: '$line'\n"; $line =~ s/(\S)-/$1 -/g; # add space before minus if needed # otherwise don't add a space print "Modified Line: '$line'\n"; my @numbers = split ' ', $line; print "Numbers are @numbers\n\n"; } =prints: Input Line: '1.234 5.6789 -1.235-4' Modified Line: '1.234 5.6789 -1.235 -4' Numbers are 1.234 5.6789 -1.235 -4 Input Line: '1.234 5.6789-12.235-4' Modified Line: '1.234 5.6789 -12.235 -4' Numbers are 1.234 5.6789 -12.235 -4 =cut __DATA__ 1.234 5.6789 -1.235-4 1.234 5.6789-12.235-4
In reply to Re: match digit, followed by hyphen, followed again by digit - then add whitespaces and replace in file
by Marshall
in thread match digit, followed by hyphen, followed again by digit - then add whitespaces and replace in file
by fasoli
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |