SPUG:Here documents
Michael R. Wolf
MichaelRunningWolf at att.net
Sat May 3 01:48:18 CDT 2003
Brian Hatch <spug at ifokr.org> writes:
> Ok, I should know the answer to this...
>
> Is there any way to allow a HERE document delimiter to be indented? Ala
In cases like this, I make "THERE documents" like this.
# This is a "THERE document".
# It's *here*, but it's needed *there*.
sub text_blahXXX {
return <<EOM;
Here's my text
ain't it fun
heeha
EOM
}
if ( blah1 ) {
while ( blah2 ) {
unless ( blah3 ) {
$something = text_blahXXX;
}
}
}
Too much PHP programming can make the code (or the template/text) look
real ugly!!! I like to separate 'em. Too many HERE documents, and it
looks too much like PHP to me.
Michael
P.S. It's a technique I created adopted from a practice I had for
shell scripts. In shell scripts, I used stdout in the function
(subroutine) and command substitution in the main body. Note, that
most folks still don't know that $(...) is a better (and newer) syntax
for backticks, `...`, even though it's not so new any more. I like it
because it's easier to see. It also nests better, though I don't tend
to nest them except to bend the brains of students in my class to show
them how beautiful they really can become. Additionally, the dollar
sign becomes "value of" in *two* contexts, makeing them easier to
rember because of the network effect.
${variable} # usually simplified to $variable
$(command)
#! /bin/ksh
function header_text {
cat <<HEADER_EOM
blah blah blah
HEADER_EOM
}
function trailer_text {
cat <<TRAILER_EOM
blah blah blah
TRAILER_EOM
}
header="$(header_text)"
trailer="$(trailer_text)"
print "$header"
#.... do a litttle loop, make a little, uh, er, report....
print "$trailer"
--
Michael R. Wolf
All mammals learn by playing!
MichaelRunningWolf at att.net
More information about the spug-list
mailing list