Hi monks, I need some help with this one as im not sure how to go about it without severely changing my code.

use strict; # the connectors in the the ping connectivity my @fromConnectors; my @toConnectors; # The ping connectivity char my @fromPing; my @toPing; # reads each line until 'General manual list' is found do { $_ = <> } until /General manual list/; <> for (1..3); # skips 3 lines from title # read input file while (<>) { last if /^\+/; # split table by pipelines assigning columns to each my ($misc1, $misc2, $from, $to, $length) = split (/\|/, $_); my ($fromConnector, $ping01) = split /\t/, $from; my ($toConnector, $ping02) = split /\t/, $to; # remove whitespace from entries $fromConnector =~ s/\s+//g; $toConnector =~ s/\s+//g; $ping01 =~ s/\s+//g; $ping02 =~ s/\s+//g; # add from connectors to respective arrays push @fromConnectors, $fromConnector; push @toConnectors, $toConnector; # add pings to respective arrays push @fromPing, $ping01; push @toPing, $ping02; } ################################################################ # # Reads in file and converts pinged conenctors to abbreviated # format required (1L, 2R etc) # ################################################################ # the number of from and to connectors are the same my $numPing = @fromConnectors; # open file that connectors are printed to my $filename = "connectorIDs.txt"; open(INFILE,"<$filename") || die "Can't open file $filename"; # put file into an array my @infile = <INFILE>; # close connectorID file close INFILE; # split the first line by spaces to get left connectors my @firstLine = split /\s+/, @infile[0]; # split the 2nd line by spaces to get right connectors my @secondLine = split /\s+/, @infile[1]; # get the number of connectors in arrays my $firstLine = @firstLine; my $secondLine = @secondLine; # initialise the arrays the converted connectors are being stored my @fromConv; my @toConv; # loop through the from connectors one at a time for (my $a = 0; $a <= $numPing; $a++) { # set the from counters so each time it looks at the # next from connector, the counter is set back my $fromLeftCounter = 1; my $fromRightCounter = 1; # read in each left connector & compare to the from connector for (my $b = 0; $b < $firstLine; $b++) { # if they are equal replace with xL and push to array # increase the counter either way if (@firstLine[$b] eq @fromConnectors[$a]) { my $leftCons = @fromConnectors[$a]; $leftCons = $fromLeftCounter."L"; push @fromConv, $leftCons; $fromLeftCounter++; } else { $fromLeftCounter++; } } # read in each right connector & compare to the from connector for (my $c = 0; $c < $secondLine; $c++) { # if they are equal replace with xR and push to array # increase the counter either way if (@secondLine[$c] eq @fromConnectors[$a]) { my $rightCons = @fromConnectors[$a]; $rightCons = $fromRightCounter."R"; push @fromConv, $rightCons; $fromRightCounter++; } else{ $fromRightCounter++; } } } # loop through the from connectors one at a time for (my $a = 0; $a <= $numPing; $a++) { # set the To counters so each time it looks at the # next To connector, the counter is set back my $toLeftCounter = 1; my $toRightCounter = 1; # read in each left connector & compare to the To connector for (my $b = 0; $b < $firstLine; $b++) { # if they are equal replace with xL and push to array # increase the counter either way if (@firstLine[$b] eq @toConnectors[$a]) { my $leftCons = @toConnectors[$a]; $leftCons = $toLeftCounter."L"; push @toConv, $leftCons; $toLeftCounter++; } else { $toLeftCounter++; } } # read in each right connector & compare to the To connector for (my $c = 0; $c < $secondLine; $c++) { # if they are equal replace with xR and push to array # increase the counter either way if (@secondLine[$c] eq @toConnectors[$a]) { my $rightCons = @toConnectors[$a]; $rightCons = $toRightCounter."R"; push @toConv, $rightCons; $toRightCounter++; } else{ $toRightCounter++; } } } # output tsv file, pings appended to line my $filename01 = "c:/CableEye/Conversion/output.txt"; open(OUTPUT,"+>>$filename01") || die "Can't open file $filename01"; print OUTPUT "\t", "\"\"", "\t", "\""; # read through each of the abbreviated arrays, pairing # the respective elements and pings. for (my $x = 0; $x < $numPing; $x++) { # if the last one do not have a space at the end if ($x eq $numPing - 1) { print OUTPUT @fromConv[$x].@fromPing[$x], ":", @toConv[$x].@to +Ping[$x], "\"", "\n"; } else { print OUTPUT @fromConv[$x].@fromPing[$x], ":", @toConv[$x].@to +Ping[$x], " "; } } # close output file close OUTPUT; # deletes the connectorID file once its been used unlink $filename;

This code reads in a table like the one below, which is inside a txt file.

+---------------------+ | General manual list | +---------------------+-----------------------------------------+----- +------------+---------------+--------+ | Type Gauge Color Referenc Id Type | FROM + | TO | Length | +---------------------------------------------------------------+----- +------------+---------------+--------+ | werww WH scr 258 ky91-02 | abc123 +1 | def123 1 | 38 | | w BU scr 258 ky91-02 | abc123 1 | + def123 2 | 38 | | WH scr 258 ky91-02 | abc123 2 | d +ef456 1 | 38 | | gg BU scr 258 ky91-02 | abc123 2 | + def456 2 | 38 | +---------------------------------------------------------------+----- +------------+---------------+--------+

It also reads in file 'ConnectorIDs.txt', which contains two lines...the first containing left connector ids and the 2nd containing right connector ids.
These are required in order to change the id's to an alias. The output is printed to output.txt in some dir.

abc123 def123 def456

Now heres the problem, as i only received printed copies of the txt files which have the table and some other junk in, i failed to notice that if the table was excessively long, it continued on the next page...with the table headers added as well. So you can see the above code will not collect the data needed for a second table, how do i make it so it does?

The table still has the same features, with 'General manual list' as a title etc.

All guidance/advice is appreciated

Thanks, Steve

update (broquaint): added <readmore> tag


In reply to read file twice by Anonymous Monk

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.