Lejocode has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I'm a total noob to perl and programing in general, and would appreciate any help to achieve what i want, and all i want is just a simple script that can be applied to any file and does two things.
first, find a matched number and replace it with a calculated value.
second, is to find a matched string and add the number of occurrence to it.
Ah, so fondly I remember when I became a PerlMonks member, And in my innocence never posted purely to be an XP Whore. Happily your code I’d borrow, and back again I’d be tomorrow Though some examples left me harrowed, harrowed and synapses sore, for my ignorance was abundant and my knowledge of the language poor, But now I’m just an XP Whore.
and to be replaced with:Ah, so fondly I remember when I became a PerlMonks member, And in my innocence never posted purely to be an XP (1) Whore. Happily your code I’d borrow, and back again I’d be tomorrow Though some examples left me harrowed, harrowed and synapses sore, for my ignorance was abundant and my knowledge of the language poor, But now I’m just an XP (2) Whore.
i did some search and that's what i found but i'm stuck and can't go any further.$^I = '.bak'; while (<>) { s/Z=(\d+),/ what do i do here? /g; s/\bXP\b/ what do i do here? /g; print }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to find a number and replace it with calculated value?
by toolic (Bishop) on Mar 03, 2017 at 13:19 UTC | |
by Lejocode (Novice) on Mar 03, 2017 at 13:33 UTC | |
by AnomalousMonk (Archbishop) on Mar 03, 2017 at 21:20 UTC | |
by Lejocode (Novice) on Mar 03, 2017 at 21:36 UTC | |
|
Re: How to find a number and replace it with calculated value?
by AnomalousMonk (Archbishop) on Mar 03, 2017 at 21:44 UTC | |
by Lejocode (Novice) on Mar 04, 2017 at 10:56 UTC |