in reply to add a line based on maxline length

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...

Replies are listed 'Best First'.
Re: Re: add a line based on maxline length
by softworkz (Monk) on Aug 01, 2002 at 15:59 UTC
    Thankz! a bunch!! All of you should me flaws with my code! and all of you were correct with what I needed. Shendal, I had to add this
    $max = $max-1; # I don't want it to count the \r|\032 print "X" x $max,"\n";
    A++ help! thankz!

    Now on to what I was thinking when I wrote it... tomhukins $vc is a left over for "variable constant" a whole other issue..
    Good idea though if I have to write the same code re-think things..

    and... redsquirrel?.. I was looking for a "shorter" version, not the "shortest" version! Thatz sick! =:-)