in reply to Re: Why does this "bad" grep work so well?
in thread Why does this "bad" grep work so well?
More importantly, the map version will be correct in the case where the substitution fails (because the element contains no comma characters). In the grep version, a failed substitution will cause the grep condition to evaluate to false, and the element will be filtered out.
FWIW, here’s my variation on the map body, adding the /r modifier to the substitution:
$i = 0; $line2 = join '', map { $i++ % 2 ? s/,/ /gr : $_ } split /"/, $line;
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Why does this "bad" grep work so well?
by BrowserUk (Patriarch) on Apr 16, 2016 at 06:49 UTC | |
by AnomalousMonk (Archbishop) on Apr 16, 2016 at 07:17 UTC |