Hi all
I'm reading in a file. Each line consists of some data, and if the line is longer that 80 chars it continues onto the next line but appends a + to that line.
foo bar foo bar foo bar...bar +foo bar
I want to reconstruct this line into a single line so I can work with it later. Here is what I came up with, but it doesn't work nicely.. Can anyone help me out..
#each element in the array is a single line my @netlist = <NETLIST>; close(NETLIST); #while it is not the end of the file while($line = shift @netlist){ chomp $line; my $tmp = $line; $line = shift @netlist; chomp $line; if ($line =~ /^\+/){ # Is this a continuation.. s/^\+//; #remove the continuation $tmp = $tmp . $line; print "$tmp \n"; }else{ pop (@netlist, $line); print "$tmp"; } }
Thanks much. If there is a simpler more <it>perlish</it> way to do this I am really open to suggestions. Additionally as some point I am going to need to reconstruct this long line so it doesn't go over 80 chars, and doesn't break up words. I am really open to suggestions here.. Thanks so much!!

In reply to Look ahead and join if the line begins with a + by Rhodium

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.