> I’m new to perl and this list. I am trying to
> create a script that cleans up csv files in
> the following ways:

search.cpan.org

There is a CVS module someplace, which might do
what you require with less hassle... or might
not.

> -Remove tab characters
> -Remove trailing commas

tr/\t//d;  # Remove tabs
s/,+$//g;  # Remove trailing commas

> -Replace ^’ character sequence with a comma

s/\^'/,/g; # Turn ^' to a comma

> -Want to preserve the CRLF and the end of each line

Automatic :)

> #My Code
> #!Perl
> $fileIN = "in.csv"; # Dirty csv file
> $fileOUT = "out.csv";

Don't use uppercase for 'Perl', it's perl in this
instance - Unix people will hate you otherwise.

You could use either @ARGV or Getopt::Long to
take these in as options rather than fixed - just
to give you a hint for the programs next steps :)

> while (<IN>) {
>             $_=~ tr/\t//d;

$_=~ is not required, can write that as:

tr/\t//d;

shorter is neater.

>             print OUT "$_";

Don't use double quotes unless you have too, it'll
mangle your data otherwise.  Just use:

print OUT;

for conciseness.

>             print "$_\n";

print $_ . "\n";

> }

Jonathan Paton

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to