On Mon, 15 Oct 2001 20:53:24 -0400, Michael G Schwern wrote: >Not only is it a bit faster than the s/^\s+//gm regex, but it is also >more flexible. > > if( $self->feeling_snooty ) { > print <<'POEM'; > Sometimes > form has to follow function > all over the page. > POEM > }
Which reminds me... one of the less attractive features of here docs is the fact that the quoted document always has to end in a newline. That is annoying at times. For example, I often use here docs as a template mechanism: convert the original text file to a here doc, split into three parts: intro, main body (loop body), outtro; and you can generate such a doc with as many repetitions as you like. If the three parts may be split right after a newline, as commonly in HTML, there's no problem. But sometimes you want to split in the middle of a line. If there was an easy way to chomp() that newline and return the remainder of the string, that would solve this too. Like this? sub chomped ($) { chomp(my $s = shift); return $s; } I don't really like this solution much. And it's not worth an extra keyword, for chomped() to become a built-in. This, in turn, reminds me of the other common problem, where s/// modifies a string, instead of returning a modified copy, as some people would like. Ain't such a chain of thoughts lovely... :-) -- Bart.