softworkz has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my $line = <DATA>; chomp($line); print "$line\n"; my $vc=0; #0 for const and 1 for var my $maxline = length($line); $_ = $line; if (m/.*\r$/){ #carriage return $maxline = $maxline - 1; } if (m/.*\032$/){ #ctrl-Z $maxline = $maxline - 1; } my $originalmaxline = $maxline; while(<DATA>) { chomp; my $newline = $_; print "$newline\n"; my $newmaxline = length($newline); if (m/.*\r$/) { #carriage return $maxline = $maxline - 1; } if (m/.*\032$/) {#ctrl-Z $maxline = $maxline - 1; } if ($newmaxline != $originalmaxline) { $vc = 1; } if ($newmaxline > $maxline) { $maxline = $newmaxline; } } #----------------------------------------------- # using the char X to see it print a space based on maxline count # in this case it's 29 #----------------------------------------------- for (my $i=0;$i<$maxline;$i++) { my $padding = "X"; print $padding; } 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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: add a line based on maxline length
by mkmcconn (Chaplain) on Jul 31, 2002 at 19:45 UTC | |
by redsquirrel (Hermit) on Jul 31, 2002 at 20:00 UTC | |
|
Re: add a line based on maxline length
by Popcorn Dave (Abbot) on Jul 31, 2002 at 20:05 UTC | |
by softworkz (Monk) on Aug 01, 2002 at 15:59 UTC | |
|
Re: add a line based on maxline length
by Shendal (Hermit) on Jul 31, 2002 at 19:57 UTC | |
|
Re: add a line based on maxline length
by tomhukins (Curate) on Jul 31, 2002 at 19:57 UTC |