in reply to what are some of the most powerful, complex, one-liners?
Hello f77coder,
I’ve always thought the regex in perlfaq5#How can I output my numbers with commas added? was pretty cool; so here it is in a one-liner:
16:56 >perl -wE "say s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\ +d))/$1,/gr for @ARGV;" 1234567 987654321098765 1,234,567 987,654,321,098,765 16:56 >
(The FAQ entry also has a commented version.)
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|