Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/bin/perl -w $xf = "~/OUTPUT" #enter file name location here <- $num =1000 #enter number of iterations here <- $tnum =20 #enter number of pdbs necessary <- $lab = "BRO" #enter label for output <- open (XF, $xf) or die "no $xf exists!!"; while (my $line = <XF>){ #reads file, takes out erroneous da +ta, if($line = m/TIMESTEP/){ #saves each chunk of 2703 line to $line = ""; #one array slot in superchunk @file = scalar(@trans); @trans[1] = @superchunk;} else if($line = m/ATOM/){ @file = $line;} } $num / $tnum = $div; for($i=1;$i<=$tnum;++$i){ open (OU, "> $lab_$i.pdb") or die "File would not open!!";); print OU (@superchunk[$i*$div]); close OU } #prints every 20th 2703 line ch +unk to #file, different file for each +chunk # close XF
this is my current script it is supposed to go through a file that is near 50 megs of text or better put is 1000 blocks of 2703 lines of coords XYZ label and number every 20th block needs to be removed and put in its own file so that it can be opened in a program that would render the coords... i have any irky feeling that this prog wont do what it should and i figured i would ask instead of beating my silicon graphics workstation with a baseball bat :) kidding if you see any problems with my method, style or just anything plz help me out :) thanx

Replies are listed 'Best First'.
Re: Breaking up large database
by rjray (Chaplain) on Jul 16, 2002 at 06:47 UTC

    I don't know any better, gentler way of saying this, but the code you posted above is very broken. As written, it won't even compile. Your first four lines are all assignment statements, and not a one has a ";" character to end the statement. Furthermore, I see nowhere where you are actually assigning any data to @trans or @superchunk. When you do:

    @trans[1] = @superchunk;

    You aren't assigning the "chunk" to the slot in @trans, the context there (caused by the left-hand-side being an array slice... did you mean that element, instead?) means that the first element of @superchunk will go into the second element of @trans, and since the slice needs no more data, no more copying will get done. Did you mean to assign the whole list contained in @superchunk, instead?

    It is very difficult to glean much more from the code, I am afraid. I apologize that I couldn't be more positive.

    --rjray

      thanx :) i am happy that you are being blunt i am used to c++ and even that i havent programed in a year i posted it cause i cant find a debugger that will debug without running it i dont want to run it cause it might actuallly due part of it but there is no way for me to see the mistake until hours of work have gone by @trans is supposed to be a one entry array i want to take that one entry and put it in to 1 slot in superchunk i will redo code maybe get a bit more right and re post :)
        You might try the -c command line option:

        perl -c script.pl

        It will check your script's syntax without executing it.

        Cheers!

        Brent

        -- Yeah, I'm a Delt.