Help parsing large files.

Stephen P Potter spp at colltech.com
Mon Dec 6 19:59:33 CST 1999


I hope no one will mind a newcomer (to the PM list, at least ;-)
trying to help out a little.

At 01:00 AM 12/7/99 +0000, Pat Collins wrote:
>         open(FCCDAT,"<$fccdata");

First of all, whenever you open a file, you always want to check the
return status of the open.  The better way to write this line would be
one of the following two ways (which are both functionally the same):

         open FCCDAT, $fccdata or die "Can't open '$fccdata': $!\n";
         open(FCCDAT, $fccdata) || die "Can't open '$fccdata': $!\n";

If you aren't conversant with the idea of short circuit operators, or of
the $! variable, feel free to drop me a line and I'll be happy to explain.

>         open(FCCOUT,">$newfccfile");


This particularly is the same as the above.  You really want to know if
a file you are trying to write to can't be opened for some reason.


>         while (<FCCDAT>) {
>
>                 s/\|/","/g; #convert | to ,

Do you really want the three characters "," or just the one character ,?
If just the one, you really want

                 s/|/,/g

>                 s/^/"/; #add initial "
>                 s/.$/"/; #add final "

This is better as just
         s/$/"/;
to make sure that you don't accidentally replace a character that you
want to keep.

>                 s/""/\\N/g; #change "" to proper mysql null value \N
>         #print STDOUT $fccdata;
>         print FCCOUT $fccdata;


I'm not sure what you are expecting from this line.  $fccdata is a variable
with a filename in it.  So basically, you're going to end up with a large file
with the filename repeated over and over and over in it.  I think what you
really meant was

         print FCCOUT $_;

-spp

--
Stephen P Potter     	spp at colltech.com		Ph: 614-766-3653
Senior Consultant	Collective Technologies		Pg: 800-946-4646
			http://www.colltech.com/	      PIN 140-4132
http://www.quixtar.com/ Referral IBO # 2631871		
http://post369.columbus.oh.us/crew.d/members.d/Adults.d/stepot.d/index.html
-----------------------------------------------------------------------
To send mail to the Columbus.pm list send email to
columbus-pm-list at happyfunball.pm.org

To unsubscribe send an email to majordomo at hfb.pm.org  with
unsubscribe columbus-pm-list youremail at yourdomain.com
-----------------------------------------------------------------------



More information about the Columbus-pm mailing list