in reply to $1 returning value from previous match
The string "Lentigo maligna melanoma [172.9]" contains a dot in the bracketed part, so the regexp doesn't match it. Therefore the variables $1 to $9 remain unaltered. (They are only set if there is a successful match.)
Try something like:
my ($diagnosisString, $diagnosisNumber) = ($diagnosis =~ /^(.*)\s\[(\d +*)\]/);
Or alternatively:
my $diagnosisString; $diagnosisString = $1 if $diagnosis =~ /^(.*)\s\[(\d*)\]/;
As a general rule, don't touch the regexp-related variables unless you know that the last match succeeded.
Update: thanks AnomalousMonk and mr_mischief for pointing out my missing $ sign in the second example. Fixed now.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: $1 returning value from previous match
by wistephens (Initiate) on Jul 24, 2014 at 14:05 UTC |