in reply to Modifying text file

Here is one way to get started using s///
use warnings; use strict; while (<DATA>) { s/(\w+)/$1,/g; print; } __DATA__ This is a word. Here is another sentence.

Prints:

This, is, a, word,. Here, is, another, sentence,.

See also perlintro

Replies are listed 'Best First'.
Re^2: Modifying text file
by torres09 (Acolyte) on Jun 05, 2013 at 12:57 UTC

    hey I have extracted my text file into an array by splitting it , so can I put it in a new array with each word terminated by comma , If we can plz tell me <\p>

      Show the code that you have so far. Then we can make specific recommendations.
        #!/usr/local/bin/perl open (MYFILE, 'test1234.txt'); while (<MYFILE>) { chomp; @myNames= split(/\t/, $_); $i=0; print "@myNames \n"; while($i<=$#myNames) { #@names12[$i]=@myNames[$i]+','; $i++; } } print "@names12 \n"; exit;

        so this is the code i was hoping if in @names12 we can have elements of @myNames ending with ',' . I am new to perl so I really appreciate you helping out

        hey if in your code I wish to write this in a new text file , how should I proceed and

        secondly if i wish to put it in word by word in an array with separation by a comma , how should I proceed

Re^2: Modifying text file
by torres09 (Acolyte) on Jun 06, 2013 at 09:56 UTC

    the problem I am having is say I have entry as -9.10 it will split it as -9,10 so it breaks one entity into two , but I want it to be a ......,-9.10,..... . so can you please help out