in reply to Crafting a regex for a split() function...
You can do it in one with:
use strict; use warnings; use constant TO_US => 0.127; while (<DATA>) { s/(\d+.\d+)/convert($1)/eg; print; } sub convert { return sprintf "%.2f", $_[0] * TO_US; } __DATA__ Hello all! Today I bought breakfast for 02.50 and lunch for 10.20 Di +nner was a real splurge at 21.00.
Prints:
Hello all! Today I bought breakfast for 0.32 and lunch for 1.30 Dinn +er was a real splurge at 2.67.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Crafting a regex for a split() function...
by chinamox (Scribe) on Nov 23, 2006 at 01:41 UTC | |
by ikegami (Patriarch) on Nov 23, 2006 at 01:46 UTC | |
by chinamox (Scribe) on Nov 23, 2006 at 02:03 UTC | |
by GrandFather (Saint) on Nov 23, 2006 at 02:30 UTC |