Well I was able to cut it down to the following. I don't know that it's any faster or not but it's less to look at. :)

#!/usr/bin/perl -w use strict; my $line; my $maxline = 0; # make sure you get the length of the first line while($line = <DATA>) { chomp($line); print "$line\n"; $maxline = length($line) if length($line)>$maxline; $maxline -= 1 if $line =~ m/.*\032$/; } #----------------------------------------------- # using the char X to see it print a space based on maxline count # in this case it's 29 #----------------------------------------------- print "X" for (1..$maxline); print "\n"; __DATA__ This is my file it doesn't have a blank line at the end of it based on the maxline count of the file that it read. <P>

A couple of things I did notice though:

1. If you're chomping the line coming in, why are you checking it for \r again? Maybe I'm overlooking something there and if so, I know someone will point it out.

2. Why are you checking the first line of data outside your loop?

3. What is all the ( what appears to be - to me anyway ) extraneous code at the top or is that another part of your program that you didn't post?

Hope that helps!

Some people fall from grace. I prefer a running start...


In reply to Re: add a line based on maxline length by Popcorn Dave
in thread add a line based on maxline length by softworkz

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.