Jenda Krynicky wrote:
>
> From: "Steven Arbitman" <[EMAIL PROTECTED]>
>
> > I have a problem which is simple to state:
> >
> > Find all prices in a file, multiply them by 2.5, and print out the
> > file with the new prices.
> >
> > It seemed like a good use for substitution at first.
> >
> > The following successfully finds the prices and saves them in memory:
> >
> > /\$([0-9.]+)/
> >
> > (a dollar sign followed by one or more digits and periods).
> >
> > However, attempting to substitute:
> >
> > s/\$([0-9.]+)/\$($1*2.5)/
>
> You want
>
> s/\$([0-9.]+)/'$' . ($1 * 2.5)/ge;
>
> The /g makes sure you change all prices, not just the first, the /e
> instructs Perl to treat the replacement not as a string, but as a
> code block.
He will also need to round or truncate to two decimal places.
s/\$([\d.]+)/sprintf '$%.2f', ($1 * 2.5)/ge;
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]