How can I convert a string number to a number in Perl?

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

Was this solution helpful to you?

Just Added Q & A:

Find solution

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.