Perl script to replace a number with its double?
-
Hi, I need a perl script to replace a string something like time 10 (number varies) to time 20.can it done using sed or awk command. Whats the best way to do this
-
Answer:
It's a fairly simple problem: $string =~ s/(?<=time )([0-9]+)/$1 * 2/e. The (?<=...) construct is a positive lookbehind. It says "match this text, don't include it in the regular expression. This ensures that the right side of the substitution only replaces the number and not the "time " text. The parentheses around the [0-9] character class capture it to the $1 variable and the /e switch at the end of the substitution says "execute the code on the right side of the substitution and replace the left side with the results of the left. However, I can't provide a full script because it's not at all clear to me what you're really trying to do.
chetnaya at Yahoo! Answers Visit the source
Related Q & A:
- How to replace a string inside of a Word Document?Best solution by Stack Overflow
- How to replace a fragment with another fragment in Android?Best solution by Stack Overflow
- How to replace a fragment of view pager with other new fragment in android?Best solution by Stack Overflow
- How do you replace a Crankshaft position sensor on a 2003 Saab 9-3?Best solution by Yahoo! Answers
- How do you replace a fuel pump in a 1996 Mercury Cougar?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.