SPUG: line breaks in format fields

dleonard at dleonard.net dleonard at dleonard.net
Fri Nov 17 13:10:09 PST 2006


Use a here-doc

my $bigTextField = <<END;
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 play bluegrass 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.
END

-- 

<Douglas Leonard>
<dleonard at dleonard.net>
<Perfect is the enemy of good. If we tried to be perfect, we'd never get
anything done.	--Linus Torvalds>

On Thu, 16 Nov 2006, 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:
>
> #!/usr/bin/perl
>
> 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 play bluegrass 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.
> ";
>
> format STDOUT =
> +--------------------------------------------------------------------+
> |  ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~   |
>    $bigTextField
> +--------------------------------------------------------------------+
> .
>
> write;
>
>
> What I end up with is:
> +--------------------------------------------------------------------+
> |   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           |
> |  play bluegrass 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.                                        |
> +--------------------------------------------------------------------+
>
> But what I want is:
> +--------------------------------------------------------------------+
> |   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           |
> |  play bluegrass 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.                                        |
> +--------------------------------------------------------------------+
>
> Is there a "trick"?
>
> Thanks!
> -Ryan
>
>
>
> --
>
> +-----------------------------+
> |     ryan at the-summit.net     |
> |  http://www.the-summit.net  |
> +-----------------------------+
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
>      POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>     MEETINGS: 3rd Tuesdays
>     WEB PAGE: http://seattleperl.org/
>



More information about the spug-list mailing list