Re: Arithmetic operation inside substitution
- From: rvtol+news@xxxxxxxxxxxx (Dr.Ruud)
- Date: Mon, 21 Jul 2008 11:19:21 +0200
"Amit Koren" schreef:
$string="blah 10 20";
I need to add 5 to the 10, and add 7 to the 20.
#!/usr/bin/perl
use strict;
use warnings;
my %add = (
10 => 5,
20 => 7,
);
while ( <DATA> ) {
s/ ( [0-9]+ ) / exists($add{$1}) ? $add{$1} : $1 /xge;
print;
}
__DATA__
blah 10 37 20 blah
--
Affijn, Ruud
"Gewoon is een tijger."
.
- References:
- Arithmetic operation inside substitution
- From: Amit Koren
- Arithmetic operation inside substitution
- Prev by Date: RE: how to convert data available from excel to hash?
- Next by Date: RE: Perl DBI->Connect: how to detect a a lost connection
- Previous by thread: Re: Arithmetic operation inside substitution
- Next by thread: Strange sorting, need some help
- Index(es):
Relevant Pages
|