Thanks. I got lots to learn about perl, thinking for the 2 hours I was
trying to solve my issue with chomp and split. I have began disecting your
reponse to learn from it. One question, the last print statement:

print $_ . "\n";

what is the significance of the .  ?  when I remove it nothing is displayed

Regards,

Dave

-----Original Message-----
From: Jonathan E. Paton [mailto:[EMAIL PROTECTED]]
Sent: Saturday, March 16, 2002 6:40 PM
To: [EMAIL PROTECTED]
Subject: Re: Cleaning poorly formated csv files


> 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]


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

Reply via email to