The code (running under Perl 5, version 26, subversion 3) that I am working on is receiving a string from a database that is formatted like so: "X-Y-Z" where X, Y, and Z are all numbers. Originally, and for the longest time, X, Y, and Z were all positive numbers. Now there has been a request to allow for negative X's.
An example of the original code is as follows:
my ($X, $Y, $Z) = split("-", $data);
The code would then operate on $X, $Y, and $Z, as well as later using $data once more, in order to provide it's final output. As there is now the possibility of negative values for X, splitting on a "-" has become problematic.
I proposed the following code:
my ($X, $Y, $Z) = ($data =~ /(-?\d*)-(\d*)-(\d*)/);
using a regular expression to more fully describe the data set that is possibly found in $data, however, this has been found to not work exactly the same as the previous usage of split.
My question is: why? Additionally: what can I do to provide the correct splitting that we're looking for here? Thank you in advance.
In reply to split versus =~ by russlo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |