I know this is so simple, but I'm still a real newbie at Perl. I'm trying to search through a space delimited text file, and replace the spaces with comma delimits. The lines of data is as such:
AAA BBB CCC DDD EEE FFF
XXX YYY ZZZ RRR GGG YYY
and I want
AAA,BBB,CCC,DDD,EEE,FFF
XXX,YYY,ZZZ,RRR,GGG,YYY
so some elements are separated by 3 spaces, some by 2 spaces, and some by 1 space.
My code looks like this
$counter = 1;
#############open test file#####################
open (TESTFILE, ">>test.txt"
;
@element=<TESTFILE>;
$lengtharray = @element;
if ($counter<$lengtharray) {
$element[$counter]=$a;
$a=~s/ /,/;
$a=~s/ /,/;
$a=~s/ /,/;
$counter++;
}
close (TESTFILE);
nothing is happending - can someone kindly help. Thanks!
Ethan
AAA BBB CCC DDD EEE FFF
XXX YYY ZZZ RRR GGG YYY
and I want
AAA,BBB,CCC,DDD,EEE,FFF
XXX,YYY,ZZZ,RRR,GGG,YYY
so some elements are separated by 3 spaces, some by 2 spaces, and some by 1 space.
My code looks like this
$counter = 1;
#############open test file#####################
open (TESTFILE, ">>test.txt"
@element=<TESTFILE>;
$lengtharray = @element;
if ($counter<$lengtharray) {
$element[$counter]=$a;
$a=~s/ /,/;
$a=~s/ /,/;
$a=~s/ /,/;
$counter++;
}
close (TESTFILE);
nothing is happending - can someone kindly help. Thanks!
Ethan