I also do not really understand your requirement and also not the relation between such requirement and your code.

A few comments on your code, though.

for ($i = 0; $i < @tablea; $i++) {
It would be more perlish, clearer and probably faster (although this probably does not matter much) to write:
for my $i (0..$#tablea) {
or, better yet, to drop altogether the $i counter and get directly the content of the line:
for my $line(@tablea) {
Please consult http://perldoc.perl.org/perlsyn.html#Compound-Statements for more information.

Counting the lines of a file:

system("wc $mcpFile > crap"); open(TABLEB,'crap'); @tableb = <TABLEB>; chomp ($tableb[0]); ($count) = (split /\s+/,$tableb[0])[1]; $numObs = $count - 9; close(TABLEB); unlink('crap');
This is probably the most contrived and unnatural way of counting the lines of a file that I have ever seen. Why don't you open the file and just count the lines? Something like this:
my $count = 0; open my $IN, "<", $mcpFile or die "unable to open $mcpFile $!"; $count++ while <$IN>; close $IN;
Well, actually, I made an explicit counter for the sake of clarity, but you don't even need the $count variable here, since Perl is maintaining a line counter for you in the $. special variable (see perlvar).

If you really want to use a system call, still don't use this crap file:

my $wc_output = `wc -l $mcpFile`;
Also observe the good practice way to open a file, with a three-argument syntax and a lexical file handle. Check open for more information.
$numLines = int($numObs/6); $remainder = $numObs - ($numLines*6);
There is a modulo operator in Perl (check perlop, especially http://perldoc.perl.org/perlop.html#Multiplicative-Operators:
my $remainder = $numObs % 6;
You are now opening the file whose lines you just counted:
open(TABLEB, $mcpFile);
I don't understand the logic of what you are trying to do, but it seems to me that you could probably open it only once. Ditto on the open syntax.
@tableb = <TABLEB>;
Nothing wrong here, but it is usually better to use the while operator to iterate line by line over the file (especially if the file is large):
while (my $line = <TABLEB>) {
which means you don't need the for loop afterwards. Ditto on the more perlish for syntax.
($PDE,$year,$month,$day,$hour,$minute,$second,$eqlat,$eqlong,$eqdepth, +$mag) = (split /\s+/,$tableb[$j])[0,1,2,3,4,5,6,7,8,9,11];
can be written simpler:
my ($PDE,$year,$month,$day,$hour,$minute,$second,$eqlat,$eqlong,$eqdep +th,$mag) = (split /\s+/,$tableb[$j])[0..9,11];
or
my ($PDE,$year,$month,$day,$hour,$minute,$second,$eqlat,$eqlong,$eqdep +th,undef, $mag) = split /\s+/,$tableb[$j];
Then, you are iterating a second time on the array:
for ($k = 0; $k < @tableb; $k++) {
Ditto on the for syntax. But why don't you do everything within the same loop?

Now to the final and probably most important advise. You may have noticed that I used throughout the my operator to declare new lexical variables. This is very important, declare your lexical variables with my. And you should use the

use strict; use warnings;
pragmas at the top of every program having more than one single line. This will enable the compiler to warn you about many of your errors, typos, dangerous or deprecated constructs, etc., and you will end up saving a lot of time.

I hope this helps.

Update, 11:14 UTC:: it appears that I read one of the OP's code lines too quickly and that the OP is not counting the lines, but the words, of the $mcpFile. But that does not really change the underlying idea that I wanted to come across.

Je suis Charlie.

In reply to Re: For Loop Output Errors by Laurent_R
in thread For Loop Output Errors by Bama_Perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.