Ok first off im going on the assumption that the files will always be the same name, second off I am assuming that you know what data you want every time. Also apparently your data file only has one line? If not then you are only getting the last line from the file each time. I have moved any ||'s and &&'s to newlines so that the code doesn't wrap so much
#!/usr/bin/perl $base1 = "C:/neaq/ArcData/bluefin/data_analysis/1994sptr/data"; $base2 = "C:/neaq/ArcData/bluefin/data_dens/1994sptr"; $outfile = "C:/some/dir/to/reports"; opendir(BASE1, "$base1") || die "Cant open $base1\nReason: $!\n"; foreach $file ( grep(/\.txt$/, readdir(BASE1)) ) { warn "Skip: No matching $file in $base2\n" && next unless (-f "$base2/$file"); open(IN, "$base1/$file") || die "Cant access $file\nReason: $!\n"; while ( <IN> ) { @data1 = ( split(/\s+/) )[1,2,3,4,5,6,7]; } close(IN); open(IN, "$base2/$file") || die "Cant access $base2/$file\nReason: $!\n"; while ( <IN> ) { $data2 = ( split(/\s+/) )[3]; } close(IN); open(OUT, ">>$outfile") || die "Cant append to $outfile\nReason: $!\n"; print OUT "@data1 $data2\n"; close(OUT); } # END foreach $file readdir(BASE1) # # or alternately to save up our data and only print once # push(@out, join(' ', "$file: ", @data1, $data2)); # then loop through out once and print it out here instead #


/* And the Creator, against his better judgement, wrote man.c */

In reply to Re: Printing Columns from Two Different Files by l2kashe
in thread Printing Columns from Two Different Files by gisrob

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.