http://qs1969.pair.com?node_id=186578


in reply to add a line based on maxline length

#!perl -w use strict; my $padding = 0; for (<DATA>){ chomp; $padding = $padding > length($_) ? $padding : length($_); } print "X" x $padding, "\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.

update Wrong idea, eh? How about this?
#!perl -w use strict; my $padding = 0; for (<DATA>){ chomp; $padding = $padding > length($_) ? $padding : length($_); print "$_\n"; } print " " x $padding, "X\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.

mkmcconn

Replies are listed 'Best First'.
Re: Re: add a line based on maxline length
by redsquirrel (Hermit) on Jul 31, 2002 at 20:00 UTC
    Surely a Perl script of that brevity can be reduced to a one-liner:

    perl -lpe '$p = length if $p < length; END {print "X" x $p}'

    --Dave