Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: add a line based on maxline length

by mkmcconn (Chaplain)
on Jul 31, 2002 at 19:45 UTC ( [id://186578]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://186578]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-20 04:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found