From: Tom Sawyer Date: 2003-02-06T22:19:53+09:00 Subject: Re: %L, %l revisited On Thursday 06 February 2003 04:45 am, Dossy wrote: > You ought to read this very well-written article on here-docs, written > by Randal Schwartz: > > Unix Review Column 12 (January 1997) > http://www.stonehenge.com/merlyn/UnixReview/col12.html good little read, thanks. did you catch the line: "Sorry for the strange indentation, but here-docs have significant leading whitespace. Grr." ;-) > My personal favorite and not commonly known feature of here-docs: > > irb(main):015:0> puts <<`SHELL` > irb(main):016:0` for i in *; do > irb(main):017:0` echo $i > irb(main):018:0` done > irb(main):019:0` SHELL > [..my files snipped..] > nil very cool too. execute and build dynamic shell scripts. does #{x} work within `shell` form of heres? > Here-docs improve clarity, usually. well, in the simple cases i think yes. but like this: for (<<'EOF' =~ /(.+)/g) { fredf:Fred Flintstone:$25 barneyb:Barney Rubble:$100 bettyb:Betty Rubble:$0.05 EOF ($email, $person, $owe) = split /:/; print < Yes, that old. > Apparently, the improvement of "<<-word" here-docs that strip leading > tabs only came two years later, in 1981: > > o here document with trailing dash "<<-" strips leading tabs well, that's interesting in its own right. the <<- is not only to allow the EOT (or what have you) to be indented, but to remove all initial tabs in the text itself. curious ruby dosen't do. i wonder if perl does....duh! first quote of this email; it would indicate perl doesn't either. that might offer an more elegant solution for HERE docs at least: puts <<-TOHERE this is untabed TOHERE this is untabbed puts <<-TOHERE this is untabed TOHERE this is untabbed of course don't ask me what would happen if one did: puts <<-TOHERE this is untabed TOHERE -- tom sawyer, aka transami transami@transami.net