Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Perl script help to convert .txt file to .csv

by Seabass (Novice)
on Dec 20, 2011 at 23:40 UTC ( #944504=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl script help to convert .txt file to .csv
in thread Perl script help to convert .txt file to .csv

Yes you are correct, my mistake

By the way, thanks for the code!

It works great, here is the complete version that reads from and writes to files.
use strict; use warnings; print "\n Running script for Jiggs \n"; my $infile = "foot.txt"; open my $in, "<", $infile or die $!; open my $out, ">", "foot1.txt" or die $!; my $line; while ( <$in> ) { chomp; s/length=//; s/xy=//g; s/region=//g; s/run=//g; tr/ /,/s; if ( /^>/ ) { print $out "$line\n" if $line; $line = $_; } else { $line .= $_; } } print $out "$line\n"; close $in; close $out; print "\n Done!\n";

Many thanks to all the responses, I learned so much today: Using RegEx's and substitution, file handling, split function, and joining arrays!


Comment on Re^2: Perl script help to convert .txt file to .csv
Download Code
Re^3: Perl script help to convert .txt file to .csv
by littlemonk (Sexton) on Jan 06, 2014 at 13:48 UTC

    try this code ..

    use strict; use warnings; open ( my $in ,"intxt.txt") || die "check the input file...not able t +o open $!"; open ( my $out ,">output.txt") || die "check the input file...not abl +e to open $!"; $/=""; my $in_whole= <$in>; $in_whole=~ s/\n//g; my @arr=split(">",$in_whole); my $fout=join(">",@arr); print $fout; $fout=~ s/>/\n>/g; $fout=~ s/^(\n)//; $fout=~ s/\s/,/g; $fout=~ s/length=//g; @arr=split(">",$fout); $fout=join(">",@arr); $fout=~ s/>/\n>/g; $fout=~ s/^(\n)//; $fout=~ s/,\n/\n/g; print $out $fout; close($in); close($out);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://944504]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2014-09-17 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (57 votes), past polls