regex - Replace multiple instances in a string in perl -


I have a case of the following use, the input exists in the file:

  Line1: A.A. BC CC DDE  

I with this

  1 2 3 4 5  

Output

  line 1: 1 2 3 4 5  

In a regular expression in Perl, I can do this

I was trying it But there was countless

  my @ arr1 = ("AA", "BB", "CC", "DD", "EE"); Open f2, $ file; My $ count = 0; While (& lt; F2 & gt;) {my $ str = $ _; $ Str = ~ s / $ arr [$ count] / $ count + 1 / g; Print to File} Close (F2);  

This does not do any idea

If I right By way of thinking, you want to change each word with each number (increment from 1 after each word). Here's the program with trial:

  #! Use / usr / bin / perl strict; Use warnings; Test :: Use more qw (no_plan); Instead of sub {my $ str = shift; My $ count = 1; $ Str = ~ s / \ w + / $ count ++ / ge; Return $ str; } (Replacement ('aa aa dd ee'), '1 2 3 4'); (Substitution ('ABCDE'), '1 2 3 4 5');  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -