use strict; use warnings; print "\n Running script for Jiggs \n"; my $infile = "foot.txt"; # <foot.txt> is not legal q +uotation in perl5 open my $in, "<", $infile or die $!; # Don't quote a variable ag +ain open my $out, ">", "foot1.txt" or die $!; my $line = <$in>; # Is $line the header? If s +o, don't call it "line" $line =~ s/\s+\Z/\n/; # When you chomp, you don't + get a "new" newline $line =~ s/ +/,/g; print $out $line; # Don't quote variable. It +now still has a newline print $out scalar <$in>; # What is this second line? + Something special? while (<$in>) { s/\s+\Z/\n/; s/ +/,/g; s/,length=/,/g; print $out $_; } close $in; close $out; print "\n Done!\n";
Note that this might up being invalid CSV. Use Text::CSV or Text::CSV_XS to ensure valid CSV output.
In reply to Re: Perl script help to convert .txt file to .csv
by Tux
in thread Perl script help to convert .txt file to .csv
by Seabass
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |