SPUG: line breaks in format fields

Colin Meyer cmeyer at helvella.org
Thu Nov 16 15:37:04 PST 2006

On Thu, Nov 16, 2006 at 02:45:20PM -0800, Ryan Allen wrote:
> Does anybody know how to get "\n" in a format field to be preserved in
> the output?  For example, suppose I have this code:

Try the handy Text::Reform module. It's smarter that Perl's builtin
formats. There's also a super-simple Text::Autoformat wrapper to



use Text::Reform;

my $bigTextField = "
I am a dynamic figure, often seen scaling walls and crushing ice. I have been known to remodel train stations on my lunch breaks, making them more efficient in the area of heat retention. I translate ethnic slurs for Cuban refugees, I write award-winning operas, I manage time efficiently.  Occasionally, I tread water for three days in a row.

I woo women with my sensuous and godlike trombone playing, I can pilot bicycles up severe inclines with unflagging speed, and I cook Thirty-Minute Brownies in twenty minutes. I am an expert in stucco, a veteran in love, and an outlaw in Peru.

Using only a hoe and a large glass of water, I once single-handedly defended a small village in the Amazon Basin from a horde of ferocious army ants.  I playbluegrass cello, I was scouted by the Mets, I am the subject of numerous documentaries. When I'm bored, I build large suspension bridges in my yard. I enjoy urban hang gliding. On Wednesdays, after school, I repair electrical appliances free of charge.

my $format = '|  [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[   |';
my $border = '+--------------------------------------------------------------------+';

print $border, form( $format, $bigTextField ), $border, "\n";

More information about the spug-list mailing list