#! /bin/perl -w use Text::Wrap; # default quote level my $quotelevel = 1; # default quote character my $quotechar = ">"; # possible quote characters my $quotechars = ">|})"; # default line width my $maxlinewidth = 72; # the complete quoting string my $quotes; # the lines my @lines; my $line; # check @ARGV for quote level if( $#ARGV >= 0 ) { if ( ( $ARGV[0] * 1 ) eq $ARGV[0] ) { # is it numeric? $quotelevel = $ARGV[0]; } } $Text::Wrap::columns = $maxlinewidth;# - 1 - (1 * $quotelevel); # read STDIN @lines = ; # determine quote level my $x; $lines[0] =~ /^([$quotechars\s]+)\s?[\w|\n]/; $x = $1; $x =~ s/\s//g; $quotelevel = length($x); # get rid of old quotes foreach $_ (0 .. $#lines) { $lines[$_] =~ s/^([$quotechars\s]+)\s?([\w|\n])/$2/; } # get rid of excess spaces foreach $_ (@lines) { s/\t/ /; # get rid of tabs # s/^\s+//; # spaces at beginning s/\s+$//; # spaces at end } # get rid of newlines $line = join(" ", @lines); # determine quotes to input $quotes = $quotechar x $quotelevel . " "; # wrap, insert quotes @lines = wrap($quotes, $quotes, $line); print @lines; print "\n";