in reply to Re: can split() use a regex?
in thread can split() use a regex?
The number itself will be put into $two, what comes before it into $one, what comes after it (except for the leading whitespace, that is dropped) into $three.my ($one, $two, $three) = split( /(\d+)\s+/, $line, 2);
So yes, if you use capturing parens in the regex for split, you'll get more return values. From the docs:
If the PATTERN contains parentheses, additional array elements are created from each matching substring in the delimiter.produces the list valuesplit(/([,-])/, "1-10,20", 3);(1, '-', 10, ',', 20)
I recommend using better variables' names.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: can split() use a regex?
by BrowserUk (Patriarch) on Jun 18, 2006 at 11:40 UTC |