[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Perl one liner requested





--- Steven Pritchard <steve@silug.org> wrote:
> > Majordomo (seems to be a 70 character limit on
> lines).
> 
> Odd, I've never heard of such a limit.

Yeah, it seems odd.  It turns out that the comment
lines are too long and when it wraps them they are
uncommented.  I wrote fixdat.pl [attached].  It worked
but it also chopped some config lines *sigh*  I guess
I'll have to have it test to see if its a comment or
not.  Fun!
 
> > Would you:
> > 
> > A. Write a Perl script to read in the lines in and
> > write them out so that the lines over 70 had the
> > proper slash at the end of the line to make it
> useable
> > by Majordomo?
> 
> Probably.
> 
>     #!/usr/bin/perl
> 
>     $chars=69; # One less than 70, to allow for the
> backslash.
> 
>     while (<>)
>     {
> 	chomp;
> 	while (length($_)>$chars)
> 	{
> 	    $space=rindex($_, " ", $chars);
> 	    $space=$chars if ($space<=0);
> 	    ($x,$y)=/^(.{$space})\s*(.*)$/;
> 	    print $x, "\\\n";
> 	    $_=$y;
> 	}
> 	print $_, "\n";
>     }
> 
> Now that's completely, utterly untested code.  YMMV.

Regular expressions - cool!  I wish I could get
comfortable with those.  I figured you'd do it in one
line though.   :-)

__________________________________________________
Do You Yahoo!?
Kick off your party with Yahoo! Invites.
http://invites.yahoo.com/
#!/usr/bin/perl 
#  author - R.Threet 8-8-00
#  fixdat.pl - program to read a Majordomo file and properly 
#  concatenate lines over 70 characters so that it can be
#  used by Majordomo without creating errors.

while(<STDIN>) {
	$in=$_;
	$length_of_line=(length($in));
	if ($length_of_line > 70) {
		$newline1 = (substr $in, 0, 70);
		$newline2 = (substr $in, 71, $length_of_line);
		print $newline1;
		print "\n";
		print "# " . $newline2;
	} else {
	print $in;
	}
}

-
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.