stefp has asked for the wisdom of the Perl Monks concerning the following question:
I restate the problem (different from the initial one): writing an integer by block of three digits separated by underscores. The custom is to start from the end because the goal is to make visible thousands, millions and so on.
The easy way:
I thought that would do it in one substitute statement: s/(\d{3})(?=(\d{3})+)$/$1_/g; No way.$_=1113333444455; $_=reverse; s/(\d{3})/$1_/g; $_=reverse; s/^_//; print;
So I simplify the statement and instrument it with a zero witdh assertion:
It acts like if the right anchor were just behind the (\d{3}). Weird. Or I just need some sleep.DB<17> $_=1113333444455; m/(\d{3})(?{ print $1 })(?=\d{3})$/ 455
-- stefp
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: bug in regexp engine?
by wog (Curate) on Sep 29, 2001 at 06:22 UTC | |
by stefp (Vicar) on Sep 29, 2001 at 22:44 UTC |