you've got a bunch of the pieces put together correctly, but there's a few areas where these individual bits don't mesh together right. You're reading two files (the
while (<INFILE>) and
while (<INFILE2>)), but you're not storing the results of those reads. In fact each run through the loop overwrites the information that was there previously. You might declare arrays outside of these loops and store the results of the splitting in them, so that you preserve the work you're doing.
You don't seem to use $mask, $x, $y, $dfront, $ftdens, $depth, $slope, $tuna, $temp or $sptr in any useful fashion; is this part of a larger script? If not, you might consider
dropping them entirely because they're not doing you any good.
It may also benefit you to drop the the chdirs and simply open the files with :
$folder2 = "C:/neaq/ArcData/bluefin/data_dens/1994sptr/";
$textfile2 = "10.06.94.txt";
open(INFILE2, "$folder2$textfile2") or
die "Cannot open: $textfile2\n";
Finally, the diamond operator doesn't do what I expect you expect it does. It runs through @ARGV (which itself gets populated with the script's) command line arguments, treating each element as a filename which gets opened, and read line by line. Since no arguments were specified, it's waiting for input on STDIN ("just hangs").
As a rough, untested outline, here's my take on the problem.
It's not fully fleshed out, but it provides a quick idea of what a solution might look like.
open FH, "first file" || die "problem with first file : $!";
@first =<FH>; # slurp into array
close FH;
open FH, "next file" || die "problem with first file : $!";
@second =<FH>; # slurp into array
close FH;
# at this point, we've got the lines of each file in two different arr
+ays.
# if it's important that they have the same number of lines, you can
# check with if (scalar (@first) != scalar (@second)) {...
#
# now start output to the third file. maybe check to see if it exists?
open OUTPUT, ">output.txt";
# since we're reading from 2 different arrays
# it's easier to use for (0..$#first) rather than foreach (@first)
# so that we can apply the element number to both arrays.
#
my $sep=","; # specifies comma separated output. this might be bad if
+your data has commas in it.
for (0..$#first) { # this is a liability if the second file has more l
+ines...
print OUTPUT join $sep, split (/\s+?/, $first($_)), split (/\s+?/,
+ $second($_));
}
close OUTPUT;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.