Greg Wardawy wrote, on Thursday, November 09, 2000 14:36
: I'm sure I've done something stupid but I can't find what. Here 
: is the situation - I have to extract the data from a text file 
: and put it into the csv file. I was thinking it's simple - just 
: capture the data you need from each line and print it to a csv 
: file. Nice and easy. Sure - but I'm missing something here, I'm 
: doing something stupid and results are as they are but not as I 
: expected them to be. Can you take a look at it and tell me 
: what's wrong? What are the other ways to extract data from a 
: text file and put it in a csv file? How can I use Text::CSV_XS 
: (I don't know this module at all)?

You included sample output at the end, but no sample input to compare
with. But we might be able to help anyway :)

: Here goes a "code":
: ##############
: #!perl -w
: open(UCC, "<ucc128.txt")                      || die "can't open 
: ucc128.txt: $!";
: open(LNTUCC, ">> lntucc128.csv")      || die "cant open 
: lntucc128.csv: $!";
: select (LNTUCC);
: while (<UCC>) {
: s/\s+$//;
: s/^\n//;
: chomp;        

Once you've done s/\s+$//, you can skip the other two. \n is part of \s,
and chomp removes \r\n or \n at the end of a line, which \s+$ already
took care of.

Do you mean to skip blank lines? How about

        next if /^$/;

after s/\s+$//.

: if (/^ORG/) {
:       #ignore
: }
: if (/^\s{6}Line\s1\s:\s(.*)/) {
:       $idd1 = $1;
:       $idd1 = "A" if length($1 == 0 ); #just checking here and below

I think you really mean

        $idd1 = "A" if length($1) == 0;

What you actually did was take $1, find its numerical value (e.g.,
12 if $1 is "12Aaoei", 0 if $1 is "abcde"), and compare that value
to 0: if true, you get '1' which has length 1; if false, you get ''
which has length 0.

So you're setting $idd1 to $1 if it starts with a non-zero number,
and to "A" if it's non-numeric text. Probably not what you meant
to do, huh?

Since you do that a lot, I'd guess that's most of your problem.
Post again (with sample input) if that doesn't give you what you
want.

Joe

==============================================================
          Joseph P. Discenza, Sr. Programmer/Analyst
               mailto:[EMAIL PROTECTED]
 
          Carleton Inc.   http://www.carletoninc.com
          219.243.6040 ext. 300    fax: 219.243.6060
 
Providing Financial Solutions and Compliance for over 30 Years

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to